469,594 Members | 2,220 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,594 developers. It's quick & easy.

Group votes into low, medium and high

I have a table with votes:
---------
| vote |
| 5 |
| 1 |
| 9 |
| 6 |
| 2 |
| 1 |
| 3 |
---------
And I would like to see number of votes between 1-3, 4-6, 7-10

This select doesnt work:
SELECT count(vote<=3), count(vote>=4 AND vote<=6), count(vote>=7)
FROM user_bfcore_vote;

/M

Jul 23 '05 #1
2 1037
On 29/03/2005, la*****@home.se wrote:
This select doesnt work:
SELECT count(vote<=3), count(vote>=4 AND vote<=6), count(vote>=7)
FROM user_bfcore_vote;


Try this instead:

SELECT
SUM(IF(vote <= 3, 1, 0)) AS LOW,
SUM(IF(4 <= vote AND vote <= 6, 1, 0)) AS MID,
SUM(IF(7 <= vote, 1, 0)) AS HIGH
FROM user_bfcore_vote
--
felix
Jul 23 '05 #2
thanks

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

61 posts views Thread by John.L.Henning | last post: by
1 post views Thread by brino | last post: by
reply views Thread by Mike Driscoll | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.