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 |
What does the on delete cascade option do?
What are the rules to use the rowguidcol property to define a globally unique identifier column?
What options are there to delete rows on the publisher and not on the subscriber? : sql server replication
How to find the service pack installed? : sql server database administration
What is change tracking in sql server?
* 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
What do you mean by data manipulation language?
Can anyone tell that the extra features are there in SQL SERVER 2008 that are not available in previous versions .
How to make a remote connection in a database?
How column data types are determined in a view?
What is difference between after and before?
What are the steps to process a single select statement?