Welcome to WebmasterWorld Guest from 22.214.171.124
Forum Moderators: open
Table A. Call it customers, friends, whatever.
Table B holds the "credits" for the entities, joins on unique_id, there can be any number of rows, and the credits can vary in amount.
Easy enough to sum() the amounts for a given entity from table A.
How do I query a count(*) on the number of people with credits > 0? Doh!
Example, table B,
The query should return a single row, a count of 2: users 1234 and 1236 have credits > 0. My meager attempts are returning multiple rows.
<feelin' sharp tonight . . . >
How do I query a count(*) on the number of people with credits > 0?
A sum of the column credits table is required to see if they have credits. So there can be entries for credits, but the sum may be zero.
Using DISTINCT unique_id should solve the problem with with zero amounts:
select count(DISTINCT unique_id) from table_b
where status=0 and
date_add(credit_date, interval 30 day) < curdate() and
amount > 0