mysql - getting data in single query -
say have following:
id bill vote 1 x 1 2 y 1 3 y 0 4 z 1 5 x 1
what want query return is:
bill vote(1) vote(0) x 2 0 y 1 1 z 1 0
vote(1) count of data (1), same applies vote(0)
select bill, sum(vote) vote_1, sum(1-vote) vote_0 tablename group bill
the first sum used sum 1's. second 1 sum 0's (1-1 = 0, 1 - 0 = 1!)
Comments
Post a Comment