P粉0381618732023-08-10 00:25:56
您可以使用LEFT JOIN語句,它會從share
表格中選擇相關行,即使在stock
表中沒有連結的行也會選擇出來。
SELECT name, 0, sum(price*quantity) / sum(quantity) as avg, sum(quantity) as qty FROM stock LEFT JOIN share ON share.stkid = stock.stkid GROUP BY stock.stkid