Showing the current week in a table
Hello,
Hopefully someone will be able to shed some light on this as I am stumped!
Basically I have a website were users enter deals into. I have two tables in my database:
One called "users" - This stores user information for example user ID username password etc.
Another table called "deals" - This stores deal information. Deal name, deal ID, user ID (which user did the deal), Deal amount, and Date the format for date is (YYYY-MM-DD).
I am now trying to display the total amount of deals done by each user for a current week for each day. For example in a 7 day calander type of style:
USERS SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
USER 1 £65 £70 £56 £38 £87 £33 £44
USER 2 £65 £70 £56 £38 £87 £33 £44
USER 3 £65 £70 £56 £38 £87 £33 £44
Hopefully this makes sense so far!
These are the sql queries i've come up with so far...
This selects each deal done in the current week:
Code:
SELECT u.firstname, d.customername, d.dealamount, d.dealdate
FROM deals d, users u
WHERE u.uid = d.useriD
AND YEARWEEK( dealdate ) = YEARWEEK( CURRENT_DATE );
For example:
USER 1 DEAL1 £65 2013-03-15
USER 1 DEAL2 £65 2013-03-16
This puts down the total sum for the week by user:
Code:
SELECT SUM( d.dealamount ) , u.firstname
FROM deals d, users u
WHERE u.uid = d.userid
AND YEARWEEK( dealdate ) = YEARWEEK( CURRENT_DATE )
GROUP BY u.firstname
For example:
USER 1 £130
Can anyone help expand on this so it comes out with current days along the top?
Thanks in advanced!