mysql - 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 是它的解决方案。
解决方案
推荐阅读
- android - 最近与 firebase android 聊天
- sql - 加入没有唯一标识符和重复数据的 SQL Server 表
- flutter - 如何使用颤振中的原始数据与 Dio 一起制作 http 帖子?
- python - 如何在虚拟环境中导入正确的 python 模块
- c# - 如何在表格的一个列单元格中输入字母,而在另一列单元格中只输入数字?
- webrtc - Webrtc远程控制手机摄像头
- java - 一个 gradle 项目中的多个项目
- vb.net - Windows 10 VB.Net 中的计划通知
- reactjs - 调度在触发它的功能中不起作用
- google-apps-script - 在 Google Apps 脚本中使用 API 列出用户的帐户标签