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

Do you know what is bit data type and whats the information that can be stored inside a bit column?

649


While using a cursor, how can you differentiate between a deleted row and a row that has been inserted with null data values?

642


How many servers can we create in a single subscription?

154


What is the web service used for reporting services?

104


What are the different type of replication in sql server?

638






Explain how to maintain a fill factor in existing indexes?

631


Explain about temporary stored procedure?

613


What is an execution plan?

659


Different types of keys in SQL?

733


What is rs.exe utility?

126


What is local temp table?

630


How to sort the query output with order by clauses in ms sql server?

736


Explain tables in SQL Azure?

106


How can sql server instances be hidden? : sql server security

681


How to insert multiple rows with one insert statement in ms sql server?

681