Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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?
Reply With Quote
  #2 (permalink)  
Old January 26th, 2011, 03:59 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
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
Reply With Quote
  #3 (permalink)  
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....
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:10 AM.


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