我有2张桌子。我需要得到这两种产品的总成本,但我不能。问题是:购物中牛奶和奶酪的总成本是多少?
表:购物
Product | Quantity –----------------- Dogfood | 1 Milk | 2 Soup | 5 Cheese | 1
表:产品
Product | Price –-------------- Fish 123 Soup 657 Dogfood 210 Eggs 230 Cheese 120 Rhubarb 255 Milk 135 Banana 200 Apples 290 Lettuce 10
我在终端上使用此查询来获取MILK和CHEESE的总价,但是当我运行它时,它不会返回任何内容。
sqlite> SELECT Quantity*Price
...> FROM products INNER JOIN shopping
...> ON products.Product = shopping.Product
...> WHERE (products.Product = 'Cheese')AND (products.Product='Milk');
答案 0 :(得分:1)
更新AND
至OR
,SUM(Quantity*Price)
SELECT SUM(Quantity*Price)
FROM products INNER JOIN shopping
ON products.Product = shopping.Product
WHERE (products.Product = 'Cheese') OR (products.Product='Milk');
答案 1 :(得分:-1)
SELECT Quantity*Price
FROM products INNER JOIN shopping
ON products.Product = shopping.Product
WHERE (products.Product = 'Cheese') **OR** (products.Product='Milk');
你试过这个吗?