Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query help group by

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-08-26 : 04:13:02
I have a table called customers and in the table is

id
date
site
namecode

How can I get a query per site and per quarter of the amount of tickets?

then the next thing i need is i have 2 more tables

payments and cancelled that have the same namecode in it.

for each record in the above query - I want the count of how many of those namecode were paid and cancelled.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-26 : 04:15:29
SELECT site,DATEPART(qq,date),your aggregate fields
FROm yourtable
GROUP BY site,DATEPART(qq,date)

i'm not sure what you want to aggregate for the grouping (you've not specified.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-26 : 04:22:47
My favorite answer!
http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-08-26 : 05:28:55
DATEPART(qq,date)

how can i get this be year and quarter so i'd have
1 2007
2 2007
3 2007
4 2007
1 2008
2 2008 etc.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-26 : 05:38:17
SELECT DATEPART(QUARTER, Col1), DATEPART(YEAR, Col1)
FROM Table1
GROUP BY DATEPART(QUARTER, Col1), DATEPART(YEAR, Col1)
ORDER BY DATEPART(YEAR, Col1), DATEPART(QUARTER, Col1)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-08-26 : 06:02:46
thanks
Go to Top of Page
   

- Advertisement -