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


Please Help Members By Posting Answers For Below Questions

What is the cartesian product of the table?

725


How to create a trigger for insert only?

765


explain different types of joins? : Sql server database administration

711


Explain cross join or cartesian product in sql?

699


What is difference between count (*) and count column?

665


What are the differences between sql server and mysql.

762


How to attach adventureworkslt physical files to the server?

823


What is the difference between cartesian product and cross join?

637


What do you mean by an execution plan? How would you view it?

694


How to check parameter value in stored procedure sql server?

661


What are the functions in sql server?

712


How to get a list of columns using the "sys.columns" view in ms sql server?

739


What is 2nf normalization form?

776


What is the architecture of ms sql reporting service?

705


How do I clean up sql server transaction log?

744