Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 22nd, 2011, 12:24 PM
Registered User
 
Join Date: Jan 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question Change the view of result

i have this query:
select count(year(hiredate)) no_of_emp, year(hiredate) hire_date from raman
group by year(hiredate)

gives below result:

no_of_emp hire_date
2 2008
3 2009
2 2010
2 2011

i need the result like below:

hiredate 2008 2009 2010 2011
no_of_emp 2 3 2 2


please let me know what should be query for this?
 
Old January 26th, 2011, 03:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

in case of using SQL 2005 & UP
Code:
select * 
from 
(SELECT YEAR(hireDate) AS Yr FROM Raman) P
PIVOT ( 
	COUNT(Yr) FOR Yr
	IN([2008], [2009], [2010], [2011]))
AS pvt
__________________
Always,
Hovik Melkomian.

Last edited by melvik; January 26th, 2011 at 07:46 AM.. Reason: forgot
 
Old January 27th, 2011, 03:12 PM
Registered User
 
Join Date: Jan 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much Hovik...i am using 2005 and this query worked absolutely perfect....





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent - Send mail with plain view and html view ashish.dadhwal ASP.NET 2.0 Professional 0 November 27th, 2008 01:49 AM
GridView and SQL More than one result = one result DarkForce ASP.NET 2.0 Basics 0 July 20th, 2007 04:29 AM
populate details view or list view non empty rows iinfoque ASP.NET 2.0 Basics 0 March 11th, 2007 06:11 AM
Report change in Design View echovue Access VBA 4 March 3rd, 2006 04:31 PM
query result page? CHANGE 1 cedwards Dreamweaver (all versions) 31 July 1st, 2005 12:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.