Hello,
I'm new to table joins and would need some help with getting this SQL query right.
I have two tables:
1. table clicks
partnerid | date | raw | unique
2. table sales
saleid | partnerid | date | amount
Now let's say I want to find out how many clicks and sales are logged for partnerid "2" between 20th July and 5th August. I tried many queries, like the one below:
SELECT A1.date, A1.raw, A1.unique, SUM(A2.amount)
FROM `clicks` A1, `sales` A2
WHERE A1.partnerid =2 AND A1.date
BETWEEN '2004-07-20' AND '2004-08-05' AND A2.date
BETWEEN '2004-07-20' AND '2004-08-05'
GROUP BY A1.date LIMIT 0 , 30
but can't get it to work. What I basically want is a result like this:
date | raw | unique | amount
----------------------------
2004-07-20 | 123 | 120 | 10.00
2004-07-21 | 59 | 52 | 5.00
2004-07-22 | 130 | 125 | 15.00
2004-07-23 | 223 | 211 | 25.00
etc.
Everything except "amount" is from table 1. "amount" should be the SUM() of all sales on that date.
Any help with this query is much appreachiated!
Thank you!
I'm new to table joins and would need some help with getting this SQL query right.
I have two tables:
1. table clicks
partnerid | date | raw | unique
2. table sales
saleid | partnerid | date | amount
Now let's say I want to find out how many clicks and sales are logged for partnerid "2" between 20th July and 5th August. I tried many queries, like the one below:
SELECT A1.date, A1.raw, A1.unique, SUM(A2.amount)
FROM `clicks` A1, `sales` A2
WHERE A1.partnerid =2 AND A1.date
BETWEEN '2004-07-20' AND '2004-08-05' AND A2.date
BETWEEN '2004-07-20' AND '2004-08-05'
GROUP BY A1.date LIMIT 0 , 30
but can't get it to work. What I basically want is a result like this:
date | raw | unique | amount
----------------------------
2004-07-20 | 123 | 120 | 10.00
2004-07-21 | 59 | 52 | 5.00
2004-07-22 | 130 | 125 | 15.00
2004-07-23 | 223 | 211 | 25.00
etc.
Everything except "amount" is from table 1. "amount" should be the SUM() of all sales on that date.
Any help with this query is much appreachiated!
Thank you!