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
Do you know what is bit data type and whats the information that can be stored inside a bit column?
While using a cursor, how can you differentiate between a deleted row and a row that has been inserted with null data values?
How many servers can we create in a single subscription?
What is the web service used for reporting services?
What are the different type of replication in sql server?
Explain how to maintain a fill factor in existing indexes?
Explain about temporary stored procedure?
What is an execution plan?
Different types of keys in SQL?
What is rs.exe utility?
What is local temp table?
How to sort the query output with order by clauses in ms sql server?
Explain tables in SQL Azure?
How can sql server instances be hidden? : sql server security
How to insert multiple rows with one insert statement in ms sql server?