假设我想获取 ID、价格和 SUM(price),它应该如下所示:
ID price sum
--------------------
1 10
1 10 20
2 20
2 20 40
3 30
3 30 60
实现这一目标的方法是什么?我的真实查询:
SELECT users.login, projects.name, time_entries.issue_id, time_entries.hours
FROM users, time_entries
INNER JOIN projects ON time_entries.project_id = projects.id
WHERE time_entries.spent_on = CURDATE() - 1
AND time_entries.user_id = users.id
ORDER BY users.login;
节目
+-------+----------------------------------------------------+----------+-------+
| login | name | issue_id | hours |
+-------+----------------------------------------------------+----------+-------+
| ach | name1 | 12624 | 8 |
| aco | name2 | 11550 | 3 |
| aco | name2 | 11585 | 3 |
| alt | name3 | 12644 | 7.5 |
| ata | name4 | 12761 | 1 |
| ata | name5 | NULL | 1 |
| ata | name6 | 12790 | 0.5 |
| ata | name7 | 12677 | 5.5 |
| ato | name8 | 12530 | 8 |
| elb | name8 | 12697 | 1 |
| elb | Software management | 12678 | 7 |
我想在第五列中获得唯一登录的小时总和。