我有这两张桌子。
----------------------------------------------- |order_id | cust_id| order_detail| order_price| |101 | 203 | Canon-XL | 4500.00 | |102 | 201 | Canon-XL | 4500.00 | |103 | 201 | Battery-L | 850.00 | |104 | 207 | EPSONL 120 | 5100.00 | |105 | 205 | EPSONL 120 | 5100.00 | |106 | 203 | Battery-S | 5100.00 | |107 | 204 | HP DESK-230 | 520.00 | |108 | 206 | TRIPOD-XL | 1550.00 | -----------------------------------------------
------------------------------ |cust_id| salary_id| salary | |201 | 101 | 3200.00 | |202 | 102 | 4100.00 | |203 | 103 | 2000.00 | |204 | 104 | 5100.00 | |205 | 105 | 5100.00 | |206 | 106 | 2500.00 | |207 | 107 | 2700.00 | ------------------------------
现在我想总结一下tb1上的order_price,其中tb2上的工资小于3000 ..
我该怎么做?
------------ |total_order | |------------| |11150 | ------------
答案 0 :(得分:0)
您可以根据cust_id
SELECT SUM(order_price)
FROM tb1
JOIN tb2 ON tb1.cust_id = tb2.cust_id
WHERE salary < 3000