首页 > 解决方案 > Mysql Query:在单个查询中推荐多少 sum()?

问题描述

我有 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 是它的解决方案。

标签: mysqlsum

解决方案


推荐阅读