---------------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 |
--------------------
我想從表colete
使得從id_lista
列的選擇,以獲得從表comenzi
從taxaComand
列總和,所以在最後的總和是32.00
如何從另一臺基於第一臺獲得SUM在MySQL
這是我有,但並不好:
SELECT a.id_comnda AS a_id_comanda, a.id_lista AS a_id_lista,
b.id AS b_id, b.taxaComanda AS b_taxaComanda
(SELECT sum(taxaComanda) FROM comenzi WHERE b.id = a.id_comanda AS totalTaxaComanda)
FROM colete a
INNER JOIN comenzi b ON b.id = a.id_comanda
WHERE a.id_lista = 3820
GROUP BY a.id_comanda
什麼是你期望的輸出? – sagi
taxaComanda:16.00 + 00.00 + 16.00 = 32.00 – oxido
爲什麼?它是如何有意義的? – sagi