Luc*_*one 5 mysql sum multiplying
有这样的表:
sold_items:
code | size | quantity
abc123 | small | 4
abc123 | medium | 2
xyz987 | small | 3
xyz987 | medium | 1
xyz987 | large | 2
Run Code Online (Sandbox Code Playgroud)
价目单价目表:
code | size | price
abc123 | small | 5
abc123 | medium | 7
abc123 | large | 9
xyz987 | small | 10
xyz987 | medium | 13
xyz987 | large | 15
Run Code Online (Sandbox Code Playgroud)
这将是你最好的(更快的查询)方法
结果:
code | sold_items | cash
abc123 | 6 | 34
xyz987 | 6 | 73
Run Code Online (Sandbox Code Playgroud)
这应该工作:
SELECT si.code, SUM(si.quantity), SUM(si.quantity * pl.price) as cash
FROM sold_items si
INNER JOIN price_list pl ON pl.code = si.code AND pl.size = si.size
GROUP BY si.code
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
122 次 |
| 最近记录: |