php - SQL : if and count doesent count second id -
i made query using if statement.its working in following database.
select date, if(id <= 5, count(*), 0)*5 + if(id >= 6 , id <=8, count(*), 0)*4 + if(id >= 9 , id <=10, count(*), 0)*5 total prepare_test group date
but problem when doesent count 2nd id
select date, if(id >= 2 , id <= 5, count(*), 0)*5 + if(id >= 6 , id <=8, count(*), 0)*4 + if(id >= 9 , id <=10, count(*), 0)*5 total prepare_test group date
it return zero. plese suggest query this. if have other method please briefly.
assuming want count number of rows having id < 2
, total number of rows, can achieved using 2 queries:
select count(*) less_than_2 plugin id < 2
and
select count(*) total plugin
or can both values using single query:
select sum(if(id < 2, 1, 0)) less_than_2 count(*) total plugin
wiki
Comments
Post a Comment