答案 0 :(得分:2)
select t1.product, t1.quantity, t1.avgprice, coalesce(t2.buyprice, 0)
from table1 t1
left join table2 t2 on t1.product = t2.product
LEFT JOIN
也会返回table1行而没有匹配的table2行。
coalesce(t2.buyprice, 0)
用于返回0。
答案 1 :(得分:0)
您只需要使用JOIN语句查询。
SELECT t1.Product, t1.Quantity, t1.AVGPrice, t2.BuyPrice
FROM Table1 t1
LEFT JOIN Table2 t2 ON t1.Product = t2.Product
答案 2 :(得分:0)
您可以使用左连接,如下所示:
SELECT t1.product, t1.quantity, t1.avgprice, ISNULL(t2.buyprice, 0)
FROM table1 t1
LEFT JOIN table2 t2
ON t1.product = t2.product