我有表格文章:
arrtno descr unit sales
1 beer 1 10
2 coke 1 12
3 beer ct 12 5
4 coke ct 12 7
和表突变
artno mutation
1 3
2 4
我需要查询啤酒的销售情况,因此它是1*10 + 12*5
。那么如何从其他表中获取变异并将其添加到基本项目中。
答案 0 :(得分:0)
试试这个
SELECT SUM(unit * sales) FROM article WHERE arrtno IN (
SELECT mutation from mutations WHERE artno IN (
SELECT arrtno FROM article WHERE descr = 'beer'
)
UNION
SELECT arrtno FROM article WHERE descr = 'beer'
)
答案 1 :(得分:0)
试试这个
SELECT b1.unit * b1.sales + b2.unit*b2.sales
FROM beer b1, beer b2, mutation
WHERE b1.artno = mutation.artno
AND b2.artno = mutation.mutation