Where In语句中的未知列'SUM(CASE WHEN')

时间:2019-10-03 06:47:21

标签: php mysql zend-framework

php升级后,我遇到了“ SUM(CASE(ID WHERE IN(array values)))”中的问题。这是我的查询,请协助我解决此问题。

问题:

  

未知列'SUM(CASE WHEN(inv.invoice_id IN   (0,171555,184955,186846,186869,187323,189013,189785,190082,190193,190487,201987,201990,201991,202918,203219,204936,205040,205333,205603,205684,205789,206089,20'   在“字段列表”中

查询:

SUM(CASE WHEN (inv.invoice_id IN (0,171555,184955,186846,186869,187323,189013,189785,190082,190193,190487)) THEN 1 ELSE 0 END )CountTotBal

更新的完整查询:

SELECT
  `inv`.`client_id`,`inv`.`account_manager_id`,
  `SUM(CASE WHEN (inv`.`invoice_id IN (0,171555,184955,186846,186869,187323,237972,237999)) THEN 1 ELSE 0 END )` AS `numofpat`,
  `count(distinct (case when (inv`.`invoice_id IN (0,171555,184955,186846,186869,187323,189013,189785,237999)) then patient_id end))` AS `CountPatProd`,
  `SUM(CASE WHEN (inv.invoice_id IN (0,171555,184955,186846,237999)) THEN 1 ELSE 0 END )` AS `CountTotBal`,
  `SUM(CASE WHEN (inv.invoice_id IN (0,171555,184955,186846,186869,187323,237999)) THEN 1 ELSE 0 END )` AS `CountRemBal`
FROM
  `invoices` AS `inv`
WHERE
  (inv.account_manager_id != 0)
GROUP BY
  `inv`.`account_manager_id`,
  `inv`.`client_id`;

0 个答案:

没有答案