Q:

Mysql trivial select query

I have next mysql table:
id | object_id | status

where object_id is not unique and status is tinyint(-1 or 1).
That is, for one object I can have several identical and / or different statuses.
I want to make SELECT query with getting object_id, COUNT of positive status (as pos) and COUNT of negative status(as neg) WHERE neg>pos;
I tried this, but i have problem with select several(vote_up and vote_down) columns from one(vote) using condition
SELECT * FROM (
    SELECT object_id, COUNT(status) as (IF(status>0,'status_up','status_down'))
    FROM object_statuses GROUP BY object_id;
) WHERE status_up<status_down;

A:

By viewing your query i guess you are trying to count the negative votes and positive votes from users and return users who have greater negative votes count. If that is the case you can use below query
SELECT object_id,
sum(status  = 1) status_up,
sum(status  = -1) status_down
FROM object_statuses
GROUP BY object_id
HAVING status_up < status_down

You cannot use WHERE clause to perform filter on aggregate results instead use HAVING clause for such operations

