Hi,
I've been trying to do some calculations using three tables:
tbl_order
---------
order_id
order_ref -------------+
order_date |
|
|
tbl_visitors |
------------ |
visitor_id |
visitor_ref ------------+
visitor_date |
|
tbl_ref |
------- |
ref ------------+
keyword
What I want to do is, I want to see number of sales, number of visitors between the dates specified grouped by REF and KEYWORD.
Following query and the queries similar to this always return the number of visitors (count(visitor_id)) and number of sales (count(order_id)) the same, which is not possible. What type of query should I use for this kind of cases? Outer join didn't help BTW.
Thank you very much.
SELECT ref, keyword, COUNT(visitor_id), COUNT(order_id)
FROM [tbl_ref]
INNER JOIN tbl_orders ON [tbl_ref].ref = tbl_orders.order_ref
INNER JOIN tbl_visitors ON [tbl_ref].ref = tbl_visitors.visitor_ref
WHERE (tbl_visitors.visitor_date BETWEEN '9/10/02' AND '9/20/02') AND (tbl_orders.order_date BETWEEN '9/10/02' AND '9/20/02')
GROUP BY [tbl_ref].ref, [tbl_ref].keyword
I've been trying to do some calculations using three tables:
tbl_order
---------
order_id
order_ref -------------+
order_date |
|
|
tbl_visitors |
------------ |
visitor_id |
visitor_ref ------------+
visitor_date |
|
tbl_ref |
------- |
ref ------------+
keyword
What I want to do is, I want to see number of sales, number of visitors between the dates specified grouped by REF and KEYWORD.
Following query and the queries similar to this always return the number of visitors (count(visitor_id)) and number of sales (count(order_id)) the same, which is not possible. What type of query should I use for this kind of cases? Outer join didn't help BTW.
Thank you very much.
SELECT ref, keyword, COUNT(visitor_id), COUNT(order_id)
FROM [tbl_ref]
INNER JOIN tbl_orders ON [tbl_ref].ref = tbl_orders.order_ref
INNER JOIN tbl_visitors ON [tbl_ref].ref = tbl_visitors.visitor_ref
WHERE (tbl_visitors.visitor_date BETWEEN '9/10/02' AND '9/20/02') AND (tbl_orders.order_date BETWEEN '9/10/02' AND '9/20/02')
GROUP BY [tbl_ref].ref, [tbl_ref].keyword