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



i have table students with fields classname,studname select * from students classname studname 1..

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

i have table students with fields classname,studname select * from students classname studname 1..

Answer / debasish

select classname,count(studentname) from students group by
classname

Is This Answer Correct ?    2 Yes 1 No

i have table students with fields classname,studname select * from students classname studname 1..

Answer / ramadass

select classname,count(*) from students group by
classname

Is This Answer Correct ?    1 Yes 0 No

i have table students with fields classname,studname select * from students classname studname 1..

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

i have table students with fields classname,studname select * from students classname studname 1..

Answer / 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

More SQL Server Interview Questions

What does the on delete cascade option do?

0 Answers  


What are the rules to use the rowguidcol property to define a globally unique identifier column?

0 Answers  


What options are there to delete rows on the publisher and not on the subscriber? : sql server replication

0 Answers  


How to find the service pack installed? : sql server database administration

0 Answers  


What is change tracking in sql server?

0 Answers  






* CREATE TABLE [dbo].[t_Colors]([ColorId] [int] NOT NULL,[ColorName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ColorDesc] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[ColorIndex] [int] NULL) ON [PRIMARY] GO * insert into [t_Colors] values(101,'Red','',1) insert into [t_Colors] values(101,'Red1','',2) insert into [t_Colors] values(102,'Blue','',1) insert into [t_Colors] values(102,'Blue1','',2) insert into [t_Colors] values(102,'Blue2','',3) * In this table i need to delete DELETE FROM t_Colors WHERE ColorIndex=1 AND ColorId=102 After delete above condition i need to update the ColorIndex set to 1 for Blue1[ColorName] and 2 for Blue2[ColorName] select * from [t_Colors] Note:- how can i get updates the ColorIndex values after delete. for example we need to update Blue1 ColorIndex set to 1 and Blue2 ColorIndex set to 2

0 Answers  


What do you mean by data manipulation language?

0 Answers  


Can anyone tell that the extra features are there in SQL SERVER 2008 that are not available in previous versions .

0 Answers   HCL,


How to make a remote connection in a database?

0 Answers  


How column data types are determined in a view?

0 Answers  


What is difference between after and before?

0 Answers  


What are the steps to process a single select statement?

0 Answers  


Categories