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
When to use Inner join & when to use subquery?
How to enable/disable indexes?
What is the difference between for xml raw and for xml auto?
How many types of objects are there?
How do I know if localdb is running?
Does table partitioning improve performance?
What is transaction server implicit?
What are the joins in sql server? : sql server database administration
what are the different stages of Report Processing?
What is log shipping? Can we do logshipping with SQL Server 7.0 - Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
What is efficiency data?
What does executeupdate return?
What is entity data services?
What are the differences between clustered and non-clustered index?
Explain magic tables in sql server?