I have it:
SELECT
posts.id,
(SELECT COUNT(*) FROM votes WHERE votes.post = posts.id) AS votesCount,
(SELECT SUM(vote) FROM votes WHERE votes.post = posts.id) AS votesUp
FROM posts WHERE posts.id = 1
How can I get the difference between voteCount and votesUp without making another SELECT? Sort of:
SELECT
posts.id,
(SELECT COUNT(*) FROM votes WHERE votes.post = posts.id) AS votesCount,
(SELECT SUM(vote) FROM votes WHERE votes.post = posts.id) AS votesUp,
votesCount - votesUp AS votesDown
FROM posts WHERE posts.id = 1
Is it possible, or do I need to call another SELECT? Thank.
By the way, sorry for my bad english.
Xkpr source
share