i have table students with fields classname,studname
select * from students
classname studname
1 xxxxx
1 yyyy
1 zzzz
2 qqqq
2 tttt
3 dsds
3 www
i want the output should be
No of students in class 1 : 3
No of students in class 2 : 2
No of students in class 3 : 2
Answer Posted / manoj pandey
select 'No of students in class ' + cast(classname as char(2)) + ' : ' + cast(count(*) as char(5)' from students group by classname
For more Interview Questions check my blog: http://sqlwithmanoj.wordpress.com/interview-questions/
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
what are user defined datatypes? : Sql server database administration
Why is there a performance difference between two similar queries where one uses union and the other uses union all?
Sql server reporting services vs. Crystal reports.
What is constraints and its types?
Do you know what is fill factor and pad index?
What are the different types of collation sensitivity?
What are group functions in query statements in ms sql server?
What are a scheduled jobs?
What do you understand by mirroring and mention the advantages of the mirroring?
What is thr feature of change data capture?
What is 1nf 2nf and 3nf?
How to modify the underlying query of an existing view?
What’s the distinction between dropping a info and taking a info offline?
What is field with example?
Explain datetimeoffset data type in sal server 2008?