php - SELECT users who have downvoted but never upvoted -
so, thought getting pretty @ mysql until ran idea:
i have table logging "votes" (aptly named votes
) these fields:
id
: vote's unique id.user
: unique user id of person voteditem
: id of item they're voting onvote
: vote cast set('up','down')
now, i'm trying come sql way find users votes downvotes. know of way write procedurally in php after querying of data out of table seems really, inefficient way when few queries find out.
ideally want result list of users have 0 upvotes (as being in table means have voted, downvote) , maybe number of downvotes they've cast.
any ideas on how should approach this?
select user, sum(if(vote='down',1,0)) numdownvotes votes group user having sum(if(vote='up',1,0))=0 -- 0 upvotes , sum(if(vote='down',1,0))>0 -- @ least 1 downvotes
i can't feel there's neat group user, vote
way though.
Comments
Post a Comment