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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -