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 / soorai ganesh

SELECT 'No of students in class '+ CONVERT
(VARCHAR,ClassName)+' : '+CONVERT(VARCHAR, COUNT(*)) FROM
students GROUP BY classname

Is This Answer Correct ?    21 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why use stored procedures in sql server?

554


What do you mean by cardinality?

494


Does partitioning ssd reduce performance?

492


what information is maintained within the msdb database? : Sql server administration

511


Will count(column) include columns with null values in its count?

668






How do indexes help, types?

554


Can the query output be sorted by multiple columns in ms sql server?

553


What is ems sql management studio? : sql server management studio

587


How to view the error log for any specific instance? : sql server database administration

582


What are locks in sql?

541


What is a view and what are its advantages?

691


How you can get a list of all the table constraints in a database?

518


Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of sp nesting are possible?

515


What are the filtered indexes?

604


What are the differences between decimal and float in ms sql server?

563