Hi
I'm having bit of a problem with retrieving the right data from my mysql database.
My query looks simply like this:
SELECT *, SUM(cc.Counter) as Count
FROM Costumer co LEFT JOIN Clickcounter cc ON (cc.CostID=co.CostumerID)
GROUP BY co.CostumerID
ORDER BY Count DESC
");
This works fine and lists the costumers with the costumer with the most visits first and so on.
But...
The Clickcounter table look like this showing how many thime their porfil has been shown each day.
CostID | Date and | Counter.
1 | 2008-08-07 | 4
1 | 2008-08-08 | 5
1 | 2008-08-09 | 2
1 | 2008-08-10 | 8
2 | 2008-08-07 | 7
2 | 2008-08-08 | 3
2 | 2008-08-09 | 1
2 | 2008-08-10 | 9
3 | 2008-08-07 | 8
3 | 2008-08-08 | 7
3 | 2008-08-09 | 2
3 | 2008-08-10 | 5
and so on...
So here comes the problem.
Instead of getting the sum of all counts by one costumer I need to only get the sum of the visits the last week.
So that the costumer who has the most visits a week back from now is listed first.
I guess that it's the "SUM(cc.Counter) as Count" I have to change, but how ?
Something about :
SUM(cc.Counter WHERE .. something about a week back from now... ) as Count
or maybe
SUM(cc.Counter WHERE (Select * from Clickcount where .. Date>= ???? )) as Count
I'm a bit lost here.
Can someone figure this out ?
best
Michael