Hello,
Hopefully someone will be able to help i've been racking my brains out all day!:S
Basically I have a table called deals and one called users it's connected via uid (user ID).
I want to display a set of results to show the deals done by users between two dates I have this working like this:
I want to add a column to the end of this to also show the total amount each user has done for the current month like this:
These select statements both work but is there a way of joining them so the results display in one statement?
Hopefully someone will be able to help i've been racking my brains out all day!:S
Basically I have a table called deals and one called users it's connected via uid (user ID).
I want to display a set of results to show the deals done by users between two dates I have this working like this:
Code:
SELECT u.username, d.dealdate, SUM(d.dealamount) as total, COUNT(d.dealamount) as dealamount
FROM users u
LEFT JOIN deals d ON u.uid = d.userid
AND d.dealdate BETWEEN '11/08/2013' AND '20/08/2013'
WHERE isadmin=0
GROUP BY u.username, d.dealdateCode:
SELECT u.username as monthuser, SUM(d.dealamount) as monthtot
FROM users u
LEFT JOIN deals d ON u.uid=d.userid
WHERE MONTH(d.dealdate) = MONTH(CURDATE())
GROUP BY u.username
ORDER BY monthtot DESC