Reputation: 153
I have this query:
SELECT gamer_id,COUNT(*) AS sum, SUM(amount) as amount
FROM sales_list
WHERE rdate BETWEEN '2012-04-01' AND '2012-04-30' AND gamer_id NOT IN
(SELECT gamer_id FROM sales_list WHERE rdate < '2012-04-01' GROUP BY gamer_id)
GROUP BY gamer_id
This query printed me "2" results and I'm looking just "1".
I have 1 gamer's that deposit 2 times in April and I don't want to count the total deposits just to count the total gamer's that deposited.
any advice?
Upvotes: 0
Views: 67
Reputation: 6222
I don't really get it, but you want the numbers of deposits of a gamer only or the amount he deposited in addition?!
This should deliver number of deposits:
SELECT gamer_id, COUNT(gamer_id) AS sum, SUM(amount) as amount
FROM sales_list
WHERE rdate BETWEEN '2012-04-01' AND '2012-04-30'
GROUP BY gamer_id
HAVING COUNT(gamer_id)>0
Edit:
SELECT DISTINCT gamer_id
FROM sales_list
WHERE rdate BETWEEN '2012-04-01' AND '2012-04-30'
AND gamer_id NOT IN (SELECT gamer_id
FROM sales_list
WHERE rdate < '2012-04-01')
GROUP BY gamer_id
Upvotes: 1
Reputation: 1204
try this:
SELECT sl.gamer_id,COUNT(*) AS sum, SUM(sl.amount) as amount
FROM sales_list sl
WHERE sl.rdate BETWEEN '2012-04-01' AND '2012-04-30' AND sl.gamer_id NOT IN
(SELECT sl1.gamer_id FROM sales_list sl1 WHERE sl1.rdate < '2012-04-01' GROUP BY sl1.gamer_id)
GROUP BY sl.gamer_id
Upvotes: 0