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

Explain the usage of floor function in sql server.

0 Answers  


How do I find information about the install locations for the various instances running on a computer?

0 Answers  


What are date and time data types in ms sql server?

0 Answers  


What is difference between global temporary tables and local temporary tables?

0 Answers   Tech Mahindra,


What are Row versions of DataRow?

0 Answers  






On a windows server 2003 active – passive failover cluster, how do you find the node which is active?

0 Answers  


PC(code, model, speed, ram, hd, cd, price) Find the hard drive sizes that are equal among two or more PCs.

6 Answers   APX,


What is in place upgrade in sql server?

0 Answers  


How to delete exactly duplicate records from a table?

0 Answers  


How to find the login name linked to a given user name?

0 Answers  


What are the types of database recovery models?

0 Answers   HCL,


What is normalization and its forms?

4 Answers   Challenger Financial,


Categories