Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 9th, 2007, 01:38 PM
sqlmaster sqlmaster is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 1 sqlmaster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 46 sec
Reputation Power: 0
Group records on quarterly basis

Hi All,
I have the fallowing columns
1.Empl id, name, score, date etc.
now i wanna find the avergae of score of an employee for each quater.I am using mysql server(i hope its obvious anyway)
How do i do that? can anybody help me.
ur help is greatly appreciated.
chinna

Reply With Quote
  #2  
Old March 27th, 2007, 02:22 AM
eralpery eralpery is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 16 eralpery User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 19 m 57 sec
Reputation Power: 0
Hi,
If you are using SQL Server 2005, it is easy by using the ROW_NUMBER OVER PARTITION syntax like the script below:

select
table01.cust_id,
table01.cust_name,
t.disposition,
t.date
from table01
left join (
select
row_number() over (partition by cust_id order by cust_id) rownum,
cust_id,
disposition,
date
from table02
) t on t.cust_id = table01.cust_id and t.rownum = 1


I hope it helps,

Eralper
http://www.kodyaz.com

Reply With Quote
  #3  
Old March 27th, 2007, 02:35 AM
eralpery eralpery is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 16 eralpery User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 19 m 57 sec
Reputation Power: 0
Hi,

You can use the below script for SQL2k



select
table01.cust_id,
table01.cust_name,
table02.disposition,
table02.date
from table01
left join (
select
cust_id,
max(date) date
from table02
group by cust_id
) t on t.cust_id = table01.cust_id
left join table02 on t.cust_id = table02.cust_id and t.date = table02.date

Eralper
http://www.kodyaz.com

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Group records on quarterly basis


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT