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

Answers were Sorted based on User's Feedback



i have table students with fields classname,studname select * from students classname studname 1..

Answer / 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

i have table students with fields classname,studname select * from students classname studname 1..

Answer / debasish

select classname,count(studentname) from students group by
classname

Is This Answer Correct ?    2 Yes 1 No

i have table students with fields classname,studname select * from students classname studname 1..

Answer / ramadass

select classname,count(*) from students group by
classname

Is This Answer Correct ?    1 Yes 0 No

i have table students with fields classname,studname select * from students classname studname 1..

Answer / samba shiva reddy . m

select 'No of students in class '+ CONVERT(VARCHAR,ClassName)+' : '+ convert(varchar,Count(studname)) from students
group by
classname order by classname

Is This Answer Correct ?    1 Yes 0 No

i have table students with fields classname,studname select * from students classname studname 1..

Answer / 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

More SQL Server Interview Questions

What do you mean by a Composite primary key?

0 Answers   Genpact,


Delete duplicate records from the table?(Table must have unique id)

7 Answers   TCS, Thomson Reuters,


Who developed sql server?

0 Answers  


Create Index myIndex On myTable(myColumn) What type of Index will get created after executing the above statement

3 Answers  


how to insert the values in 5 table at a time Using any single statement ?

6 Answers   Infosys, Value Labs,






What is the difference between varchar and varchar(max) datatypes?

0 Answers  


What are the dmvs?

0 Answers  


Do you know spatial data types - geometry and geography in sql server 2008?

0 Answers  


What are the five major components of a dbms?

0 Answers  


What is the difference between a local and a global variable?

5 Answers  


What are the difference between data length and length in SQL Server-2008?

3 Answers   Scio Healthcare,


How do you rename a table in sql server?

0 Answers  


Categories