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 differences between sql server and mysql.
what is the difference between Delete and Truncate command in SQL
What is resource db in sql server?
How to create a view and a stored procedure in ms sql server using "create view/procedure" statements?
How to create hyperlink from returned sql query ?
Why do you want to join software field as you have done your BE in Electronics?
How do clustered indexes store data?
What does top operator do?
What does executeupdate return?
What is raid and what are different types of raid levels?
What is inline table-value user-defined function?
your sql server is running out of disk space. You notice that there are several large files with ldf extensions what are these files? : Sql server administration
how we use window authentication connection with sql server.?
What are the differences between triggers and stored procedures?
What is spid in sql server profiler?