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
How can you transfer data from a text file to a database table? Or how can you export data from a table to a comma delimited (csv) file? Or how can you import data from ms access to a table in a database? Or how can you export data from a table to an excel file?
What is resultset concur_updatable?
Explain some stored procedure creating best practices or guidelines?
Will count(column) include columns with null values in its count?
What are the options which must be set to allow the usage of optimistic models?
Why we use the openxml clause?
Explain error handling in ssis?
Can you index views?
Does the unique constraint create an index?
What is bulkcopy in sql?
What does set rowcount do?
What are “lock” hints?
What is the default schema of your login session in ms sql server?
How many types of dimensions are there and what are they? : sql server analysis services, ssas
How you can minimize the deadlock situation?