michaela18
Technical User
I want to be able to run a query for an entire month but the date is really confusing as to how I would write this query.
Originally I wanted to write it as:
This code only works for days from tuesday - friday because the data is 1 day ahead, so tuesday is actually monday's data and friday is thursday's data. So is the maildate is on a monday, it would include the data for the friday and saturday before.
So in order to put in the figures for friday and saturday, I need to add in an extra line like this;
from history
where maildate = '20100222' --a monday
and reDate <= '20100219 - friday
from history
where maildate = '20100222' --a monday
and reDate >= '20100220 - Saturday
So for a full week, I would need to run 3 different queries. Sunday is nothing.
Any Ideas
Originally I wanted to write it as:
Code:
select maildate,
COUNT (CASE WHEN CodeList LIKE '%23412%'
OR CodeList LIKE '%12341%'
THEN 1
END) AS 'A',
COUNT (CASE WHEN CodeList LIKE '%1234112%'
OR CodeList LIKE '%46563%'
THEN 1
END) AS 'b'
from history
where maildate between '20100201' and '20100228'
This code only works for days from tuesday - friday because the data is 1 day ahead, so tuesday is actually monday's data and friday is thursday's data. So is the maildate is on a monday, it would include the data for the friday and saturday before.
So in order to put in the figures for friday and saturday, I need to add in an extra line like this;
from history
where maildate = '20100222' --a monday
and reDate <= '20100219 - friday
from history
where maildate = '20100222' --a monday
and reDate >= '20100220 - Saturday
So for a full week, I would need to run 3 different queries. Sunday is nothing.
Any Ideas