![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a SELECT statement similar to the following: SELECT YEAR(transaction_date) AS y,WEEK(transaction_date) AS w, COUNT (*) AS c FROM transaction_data_view WHERE mid = 300 GROUP BY YEAR(transaction_date),WEEK(transaction_date) ORDER BY YEAR(transaction_date),WEEK(transaction_date); The ONLY problem, here, is that if New Years day occurs in the middle of the week, that week's data will be split at the first second of the New Year. Of course, my real select statement is much more complex than this, involving joins of both tables and views (and it is quick), but this suffices to make the only remaining problem obvious. If it matters, this is being done in MySQL. So, how, then, can I fix the GROUP BY and ORDER BY clauses? |
#3
| |||
| |||
|
|
I have a SELECT statement similar to the following: SELECT YEAR(transaction_date) AS y,WEEK(transaction_date) AS w, COUNT (*) AS c FROM transaction_data_view WHERE mid = 300 GROUP BY YEAR(transaction_date),WEEK(transaction_date) ORDER BY YEAR(transaction_date),WEEK(transaction_date); The ONLY problem, here, is that if New Years day occurs in the middle of the week, that week's data will be split at the first second of the New Year. Of course, my real select statement is much more complex than this, involving joins of both tables and views (and it is quick), but this suffices to make the only remaining problem obvious. |
|
If it matters, this is being done in MySQL. So, how, then, can I fix the GROUP BY and ORDER BY clauses? Thanks, Ted |
#4
| |||
| |||
|
|
I have a SELECT statement similar to the following: SELECT YEAR(transaction_date) AS y,WEEK(transaction_date) AS w, COUNT (*) AS c FROM transaction_data_view WHERE mid = 300 GROUP BY YEAR(transaction_date),WEEK(transaction_date) ORDER BY YEAR(transaction_date),WEEK(transaction_date); The ONLY problem, here, is that if New Years day occurs in the middle of the week, that week's data will be split at the first second of the New Year. Of course, my real select statement is much more complex than this, involving joins of both tables and views (and it is quick), but this suffices to make the only remaining problem obvious. If it matters, this is being done in MySQL. So, how, then, can I fix the GROUP BY and ORDER BY clauses? Thanks, Ted |
#5
| |||
| |||
|
|
The ONLY problem, here, is that if New Years day occurs in the middle of the week, that week's data will be split at the first second of the New Year. * |
#6
| |||
| |||
|
|
Ted, The ONLY problem, here, is that if New Years day occurs in the middle of the week, that week's data will be split at the first second of the New Year. A nobody said it yet: a calendar table often might help in such a situation. A web search brings up some samples how to construct that. Basically you create a table holding all date values in which your busineess might occurr. Then you add columns for the week number and whatever you else may need. Then a simple JOIN operation on the date columns helps to get the desired week number out of the calendar table. brgds Philipp Post |
#7
| |||
| |||
|
|
Since a function is just a relation with particular qualities, what is the theoretical difference between joining to a table to get the WEEK and calling a WEEK function? |
#8
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |