简体   繁体   中英

How to get the total price from 2 tables (the quantity and price)

I have 2 tables. I need to get total cost of these 2 products but I can't. The question was: What is the total cost of Milk and Cheese from the shopping?

Table: Shopping

Product | Quantity
–-----------------
Dogfood | 1
Milk    | 2
Soup    | 5
Cheese  | 1

Table: Products

Product | Price
–--------------
Fish      123
Soup      657
Dogfood   210
Eggs      230
Cheese    120
Rhubarb   255
Milk      135
Banana    200
Apples    290
Lettuce    10

I am using this query on the terminal to get the total price of MILK and CHEESE, but when I run it, it doesn't return anything.

sqlite> SELECT Quantity*Price
...> FROM products INNER JOIN shopping
...> ON products.Product = shopping.Product
...> WHERE (products.Product = 'Cheese')AND (products.Product='Milk');

Update AND TO 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');
SELECT Quantity*Price
FROM products INNER JOIN shopping
ON products.Product = shopping.Product
WHERE (products.Product = 'Cheese') **OR** (products.Product='Milk');

have you tried this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM