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
What are the different types of columns types constraints in the sql server?
What is the difference between function and stored procedure in sql server?
What is transactional replication?
When should you use an instead of trigger?
Explain about Joins?
How are the unique and primary key constraints different?
What is Replication?
You want your report to display a hyperlink that will take users to your intranet. How do you configure such a hyperlink?
What are the kinds of subquery?
What is report subscription?
Explain the concept of view and Types of views in SQL server?
What is auditing in sql server?
What is the user of Primary key?
Explain the xml support sql server extends?
In how many ways you can invoke ssrs reports?