---------------colete--------------------
| id | id_comanda | status | id_lista |
----------------------------------------
| | 21775 | 0 | 3820 |
----------------------------------------
| | 21776 | 0 | 3820 |
----------------------------------------
| | 21777 | 0 | 3820 |
----------------------------------------
-----comenzi--------
| id | taxComanda |
--------------------
|21775| 16.00 |
--------------------
|21776| 00.00 |
--------------------
|21777| 16.00 |
--------------------
我希望从表taxaComand
中的comenzi
列中获取SUM,方法是从表id_lista
中选择colete
列,因此最后的SUM为{ {1}}
这就是我所拥有的,但并不好:
32.00
答案 0 :(得分:1)
根据您的评论,我看不到其他答案:
SELECT SUM(b.taxComanda )
FROM colete a
INNER JOIN comenzi b ON b.id = a.id_comanda
WHERE a.id_lista = 3820
答案 1 :(得分:0)
使用子查询和分组id_lista:
SELECT id_lista, SUM(taxComanda ) as result,
FROM(
SELECT id_comanda , status , id_lista, taxComanda
from colete
left join comenzi on colete.id = comenzi.id_comanda)as sq
group by sq.id_lista