gpt4 book ai didi

MySQL WITH ROLLUP 没有显示我的预期

转载 作者:行者123 更新时间:2023-11-29 02:02:58 27 4
gpt4 key购买 nike

我正在尝试向我的 SELECT 查询中添加一些总计,但我正在努力了解为什么这不起作用:

SELECT 客户,job_type,actual_value_fee
FROM jo2细节
GROUP BY 客户端,job_type WITH ROLLUP

这是我期望看到的:

+--------+----------+------------------+
| client | job_type | actual_value_fee |
+--------+----------+------------------+
| 110 | 2 | 1250 |
| 110 | 20 | 200 |
| 110 | | 1450 |
| 228 | 27 | 1000 |
| 228 | | 1000 |
| 229 | 32 | 0 |
| 229 | | 0 |
| | | 2450 |
+--------+----------+------------------+

但这是我得到的:

+--------+----------+------------------+
| client | job_type | actual_value_fee |
+--------+----------+------------------+
| 110 | 2 | 1250 |
| 110 | 20 | 200 |
| 110 | | 200 |
| 228 | 27 | 1000 |
| 228 | | 1000 |
| 229 | 32 | 0 |
| 229 | | 0 |
| | | 0 |
+--------+----------+------------------+

这是表格:

CREATE TABLE `jo2details` (
`ref` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ID` int(11) unsigned NOT NULL,
`client` int(11) unsigned NOT NULL,
`job_type` int(11) unsigned DEFAULT NULL,
`actual_value_fee` decimal(11,2) DEFAULT NULL,
`last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ref`),
UNIQUE KEY `ref` (`ref`,`ID`),
UNIQUE KEY `ref_2` (`ref`,`ID`,`client`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=413 ;

非常感谢所有帮助!

最佳答案

试试这个:

SELECT client, job_type, sum(actual_value_fee)
FROM jo2details
GROUP BY client, job_type WITH ROLLUP

关于MySQL WITH ROLLUP 没有显示我的预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11668672/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com