Table student containing 2 columns,Join date,Employee name.
Under join date 4 rows r ter =1-jan-2008,2-feb-2008,3-mar-
2008,4-feb-2008.Under Employee name 4 difeerent names
jaison,robin,binoy,rahul
Result set is,
Table containing 4-column name=jan,feb,mar,april,,beneath
these months count is given as 1,2,1,0 means these counts
representing number of emplooyees joined in a month(january
1employee,february 2 employee,march 1 employee,april 0
employee)
Can you give me the required sql query
Answer Posted / soorai ganesh
Hi dude, If u use SQLSERVER 2005 this will help u.......
-------------------------------------------------------
Create table student (studName varchar(50), doj smalldatetime)
insert into student values('Ganesh','05/26/2008')
insert into student values('Ramesh','03/26/2008')
insert into student values('Dinesh','03/26/2008')
insert into student values('Suresh','04/26/2008')
Select * from student
SELECT 'Students Admission by Monthwise',[3] AS March,[4] AS April,[5] AS May
FROM(
SELECT studName,
Month(doj) monthname
FROM student
) A
PIVOT
(
COUNT(studname)
FOR monthname in
([3],[4],[5])
) AS PVT
| Is This Answer Correct ? | 12 Yes | 1 No |
Post New Answer View All Answers
What are the various Operating system files that every SQL server 2005 database has and what is the purpose.
Do you know sql server 2008 backup compression?
What is the difference between a stored procedure and a user defined function?
Why functions are used in sql server?
How sql server executes a statement with nested subqueries?
What do you mean by sql server agent?
How to select all columns of all rows from a table with a select statement in ms sql server?
What is the use of nvl work?
How to optimize stored procedure optimization?
Help!!!!!!!!!!!! My database has gone offline, it is highlighted as 'Suspect'. Foolishly, i haven't got a recent back up. Is there a way of quickly restoring the database? Thank you
Data is not being delivered to subscribers, what can be the possible reasons? : sql server replication
How to modify the underlying query of an existing view?
How to insert data into an existing table?
sql database suspect We have a sql database that is showing as suspect. How can we recover?
what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration