我有70种不同类型的帐户。而且我正在根据帐户类型获取数据。
这样的查询
$mainData = "SELECT
count(*) AS totalRows,sum(pay) as totalPay
sum(case when account_type = 1 then 1 else 0 end) AS account_1_Total,sum(case when account_type = 1 then pay else 0 end) AS account_1_Pay,sum(case when account_type = 2 then 1 else 0 end) AS account_2_Total,sum(case when account_type = 2 then pay else 0 end) AS account_2_Pay,{all_account_types_here}
FROM account_table";
最后,这些 sum()大约有140多个。
问题是,在单个查询中推荐多少个 sum()?
谢谢!
已编辑
:GROUP BY是它的解决方案。