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
Answers were Sorted based on User's Feedback
Answer / soorai ganesh
SELECT 'No of students in class '+ CONVERT
(VARCHAR,ClassName)+' : '+CONVERT(VARCHAR, COUNT(*)) FROM
students GROUP BY classname
Is This Answer Correct ? | 21 Yes | 0 No |
Answer / debasish
select classname,count(studentname) from students group by
classname
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / ramadass
select classname,count(*) from students group by
classname
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / 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 |
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 |
How do you find value of first column before inserting value into the second column in the same table for checking that second column must have different value than first column.
what are defaults? Is there a column to which a default can't be bound? : Sql server database administration
Define Unique Key?
Let us say the SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
What is in place upgrade in sql server?
What is cursors? And what are the different types of cursor?
what is normalization? Explain different levels of normalization? : Sql server database administration
can we give the identity for existing column of the table? (already table contains 10(1-10) unique randam records)
What are actions, how many types of actions are there, explain with example? : sql server analysis services, ssas
explain different types of jions with examples briefly?
2 Answers Accenture, Excellence, Zensar,
what is raid? : Sql server database administration
Do you know clustered and non-clustered index?