выполнить селект в вложенными запросами и ифами
на выходе получаю ошибку
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
как от этого избавиться?
select sum(sum_new_sim) as prihod, sum(sum_iss_sim) as rashod, sum(sum_pers_iss_sim) as person, sum(sum_list_iss_sim) as lists, region as reg,
(if((select ost_new_sim from stat_totals where region = 'Белгород' and native_priziv = 'Весна 2017' and operator = 'мтс' and `date` BETWEEN '2017-08-28' AND '2017-09-30' order by `date` desc limit 1 )is null,0, (select ost_new_sim from stat_totals where region = 'Белгород' and native_priziv = 'Весна 2017' and operator = 'мтс' and `date` BETWEEN '2017-08-28' AND '2017-09-30' order by `date` desc limit 1 ))) +
(if((select ost_new_sim from stat_totals where region = 'Белгород' and native_priziv = 'Весна 2017' and operator = 'билайн' and `date` BETWEEN '2017-08-28' AND '2017-09-30' order by `date` desc limit 1 )is null,0, (select ost_new_sim from stat_totals where region = 'Белгород' and native_priziv = 'Весна 2017' and operator = 'билайн' and `date` BETWEEN '2017-08-28' AND '2017-09-30' order by `date` desc limit 1 ))) +
(if((select ost_new_sim from stat_totals where region = 'Белгород' and native_priziv = 'Весна 2017' and operator = 'мегафон' and `date` BETWEEN '2017-08-28' AND '2017-09-30' order by `date` desc limit 1) is null,0, (select ost_new_sim from stat_totals where region = 'Белгород' and native_priziv = 'Весна 2017' and operator = 'мегафон' and `date` BETWEEN '2017-08-28' AND '2017-09-30' order by `date` desc limit 1)))+
(if((select ost_new_sim from stat_totals where region = 'Белгород' and native_priziv = 'Весна 2017' and operator = 'ТЕЛЕ2' and `date` BETWEEN '2017-08-28' AND '2017-09-30' order by `date` desc limit 1 ) is null,0, (select ost_new_sim from stat_totals where region = 'Белгород' and native_priziv = 'Весна 2017' and operator = 'ТЕЛЕ2' and `date` BETWEEN '2017-08-28' AND '2017-09-30' order by `date` desc limit 1 )))
as ost from stat_totals where region = 'Белгород' and `date` BETWEEN '2017-04-01' AND '2017-09-30' order by `date` desc limit 1;