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

What is a non-clustered index?

642


What is the difference between varchar and nvarchar datatypes?

658


What is full outer join in sql server joins?

640


How retrieve field names from the table in SQL through JAVA code?

1476


Explain system scalar functions?

664






Explain what is it unwise to create wide clustered index keys?

611


Describe in brief authentication modes in sql server.

654


What is a document index?

674


Explain the disadvantages/limitation of the cursor?

640


Explain the Ways to improve the performance of a sql azure database?

72


What types of replication are supported in sql server?

654


What is microsoft sql server?

621


What is sql injection? How to protect against sql injection attack?

641


How to convert character strings into numeric values?

683


What is the difference between executequery () and executeupdate ()?

613