我有一个关于从我的场景中找到正确值的问题。 我有两个这样的表:
类次表
shift_id | shift_user | gate
-------- | ---------- | ------
1 | 1001 | 1
1 | 1001 | 2
1 | 1001 | 3
2 | 1002 | 1
2 | 1002 | 2
2 | 1002 | 3
3 | 1003 | 1
3 | 1003 | 3
交易表
id | shift_id | sale | gate
-----|------------|---------|----------
1 | 1 | 2000 | 1
2 | 1 | 30000 | 2
3 | 1 | 40000 | 3
4 | 2 | 300 | 1
5 | 2 | 4000 | 2
6 | 2 | 3200 | 3
7 | 3 | 5500 | 1
8 | 3 | 100000 | 3
如何计算每个shift_id的销售额总和?
请提供一个好的查询方式。
非常感谢。
:)
编辑
从答案的评论部分可以清楚地看出,我们需要获得特定类次的销售额总和。
最佳答案
使用如下查询:
Select s.shift_id, sum(sale) from shift s INNER JOIN transaction
ON s.shift_id=t.shift_id group by s.shift_id
关于mysql - 如何在mysql中找到正确的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44870373/