我正在尝试在我的SELECT
查询中添加一些总计,但我很难理解为什么这不起作用:
SELECT client, job_type, actual_value_fee
FROM jo2details
GROUP BY client, 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 ;
非常感谢所有帮助!