Q1返回固定价格的产品(where子句)
有表Products
prod_id | prod_name | prod_price |
---|---|---|
从 Products 表中检索产品 ID(prod_id)和产品名称(prod_name),只返回价格为 9.49 美元的产品。
【示例结果】返回prod_id和prod_name
SELECT prod_id,prod_name FROM Products WHERE prod_price = 9.49
Q2返回更高价格的产品
编写 SQL 语句,从 Products 表中检索产品 ID(prod_id)和产品名称(prod_name),只返回价格为 9 美元或更高的产品。
SELECT prod_id,prod_name FROM Products WHERE prod_price >= 9
Q3 返回产品并且按照价格排序(BETWEEN)
编写 SQL 语句,返回 Products 表中所有价格在 3 美元到 6 美元之间的产品的名称(prod_name)和价格(prod_price),然后按价格对结果进行排序
The BETWEEN operator is inclusive: begin and end values are included.
SELECT prod_name,prod_price FROM Products WHERE prod_price BETWEEN 3 AND 6
Q4返回更多产品(HAVING ,GROUP BY)
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
OrderItems表含有:订单号order_num,quantity产品数量
问题从 OrderItems 表中检索出所有不同且不重复的订单号(order_num),其中每个订单都要包含 100 个或更多的产品。
SELECT order_num FROM OrderItems GROUP BY order_num HAVING SUM(quantity) >= 100