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 is the cartesian product of the table?
How to create a trigger for insert only?
explain different types of joins? : Sql server database administration
Explain cross join or cartesian product in sql?
What is difference between count (*) and count column?
What are the differences between sql server and mysql.
How to attach adventureworkslt physical files to the server?
What is the difference between cartesian product and cross join?
What do you mean by an execution plan? How would you view it?
How to check parameter value in stored procedure sql server?
What are the functions in sql server?
How to get a list of columns using the "sys.columns" view in ms sql server?
What is 2nf normalization form?
What is the architecture of ms sql reporting service?
How do I clean up sql server transaction log?