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 voted
  • item: id of item they're voting on
  • vote: 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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -