I have a table named login with the fields id and success (0 or 1).
I need to return only the ids where there are more entries with success at 1 than 0 (for each id).
So far I have only been able to make a query for #success, another for #hits and another that compares if #hits > #fail
/*returns: id, #hits */
SELECT id, count(*) AS hits
FROM login u
WHERE u.success = 1
GROUP BY id;
/*returns: id, #fails*/
SELECT id, count(*) AS fails
FROM login u
WHERE u.success = 0
GROUP BY id;
/*returns id, #hits, #fails, #hits > #fails? */
SELECT id, SUM(success = 1) AS 'Hits' , SUM(success = 0) AS 'Fails', SUM(success = 1) > SUM(success = 0) as 'hits > fails?'
FROM login u
GROUP BY id;
Having just one field, I can't make any direct comparison.
Is there any way to compare values from query 1 and query 2?
Can I change query 3 to just return where SUM(success = 1) > SUM(success = 0)?
Thank you in advance.