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 / samba shiva reddy . m

select 'No of students in class '+ CONVERT(VARCHAR,ClassName)+' : '+ convert(varchar,Count(studname)) from students
group by
classname order by classname

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does server sql treat char as a variable-length or fixed-length column?

589


Explain hostprotectionattribute in sql server 2005?

602


Explain a differential backup?

575


Introduction of rollup clause using sum and group by clause?

542


query processing

1741






Explain how does the report manager work in ssrs?

501


How to move database physical files in ms sql server?

534


What is raiseerror? What is raiseerror?

648


What are system databases in ms sql server?

540


What are sub reports and how to create them?

99


What is triggers and its types?

548


What is subquery? Explain the properties of a subquery?

513


What is the default sql server instance name?

561


What is a field in a table?

582


What is sqlservr.exe - process - sql server (sqlex?press)?

604