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


Please Help Members By Posting Answers For Below Questions

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?

567


What is resultset concur_updatable?

586


Explain some stored procedure creating best practices or guidelines?

525


Will count(column) include columns with null values in its count?

670


What are the options which must be set to allow the usage of optimistic models?

519






Why we use the openxml clause?

547


Explain error handling in ssis?

573


Can you index views?

509


Does the unique constraint create an index?

568


What is bulkcopy in sql?

562


What does set rowcount do?

514


What are “lock” hints?

593


What is the default schema of your login session in ms sql server?

592


How many types of dimensions are there and what are they? : sql server analysis services, ssas

566


How you can minimize the deadlock situation?

555