Jump to content

Count if type = 42


mentalist

Recommended Posts

Sure you can compute a value and group on the computed column.

 

SELECT IF(type >39 AND type <46, 40, type) types, count(*) FROM foo GROUP BY types;
To omit values other than 13 and your range just add a where clause.

 

SELECT IF(type >39 AND type <46, 40, type) types, count(*) 
FROM foo 
WHERE type = 13 OR type BETWEEN 40 AND 45
GROUP BY types;
Link to comment
https://forums.phpfreaks.com/topic/295983-count-if-type-42/#findComment-1510436
Share on other sites

If you try and alias the name of the computed column back to the same name as the original column, it won't work correctly. Your computed name (and the name you use in the GROUP BY) have to be the computed name.

 

I'm not sure if there's a way to finesse this issue, although Barand might know.

 

With that said, it doesn't explain your result. To get only one group, there seems to be something wrong with your GROUP BY or your WHERE clause.

Link to comment
https://forums.phpfreaks.com/topic/295983-count-if-type-42/#findComment-1510451
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.