Omkar Ghurye :
Caius Jard :
Per comment:
select name, SUM(billtran.quantity) from product inner join billtran on product.id=billtran.productid where product.id in(select id from product)
GROUP BY NAME
My additions in caps
Note: where product.id in(select id from product)
is an entirely useless where clause and should be removed. Queries don't have to have a where clause and don't need one that says a table id should be in all the ids in that table (always true)
I would hence have written this one as:
SELECT
p.name,
SUM(b.quantity) as sumof_quantity
FROM
product p
INNER JOIN billtran b ON p.id=b.productid
GROUP BY
p.name
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=402021&siteId=1