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.
| Author |
Topic |
|
DaveyB
Starting Member
10 Posts |
Posted - 2008-06-04 : 03:12:32
|
Hi all,I am trying to count the total amount of times the primary key is used within each month of the year "JAN", "FEB" "MAR"... Unfortunately I have no idea how to A) Search by month and B) Count the total amount of times data within the new table that is created AFTER the outer joins are done. I hope you can help.Thanks.SELECT *FROM tableA ta, tableB tb, tableC tcWHERE tc.updated_date >= TO_DATE ('01/05/2008 00:00:00','DD/MM/YYYY HH24:MI:SS')AND tc.updated_date <= TO_DATE ('31/05/2008 00:00:00','DD/MM/YYYY HH24:MI:SS') AND tc.primaryKey = tb.primaryKey (+) AND tc.primaryKey = ta.primaryKey (+) AND count(tc.priarykey) -- This is what I want to count; |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-04 : 03:39:54
|
You should ask ORACLE questions over at dbforums.comThis is a Microsoft SQL Server forum. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-04 : 03:43:32
|
[code]SELECT DATENAME(MONTH, tc.updated_date) AS theMonthName, DATEPART(YEAR, tc.updated_date) AS theYear, COUNT(tc.PrimaryKey) AS theCountFROM tableA AS taLEFT JOIN tableB AS tb ON tb.primaryKey = ta.primaryKeyLEFT JOIN tableC AS tc ON tc.primaryKey = ta.primaryKeyWHERE tc.updated_date >= '20080101' AND tc.updated_date < '20090101'GROUP BY DATENAME(MONTH, tc.updated_date), DATEPART(MONTH, tc.updated_date), DATEPART(YEAR, tc.updated_date)ORDER BY DATEPART(YEAR, tc.updated_date), DATEPART(MONTH, tc.updated_date)[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|
|
|