typora-copy-images-to: SQL 练习题
SQL基础教程 练习题 Chapter 3
3.1
- 请指出下列 select 语句中的错误:
SELECT product_id, SUM(product_name)
-- 本SELECT语句中存在错误。
FROM Product
GROUP BY product_type
WHERE regist_date > '2009-09-01';
# where 子句的位置错误 必须在group by 子句之前
# group by 中未指定的列不能书写在select 语句中
# product_name 为字符型的列,不可以作为sum函数的参数
3.2
- 请编写一条SELECT 语句,求出销售单价(sale_price 列)合计值是
进货单价(purchase_price 列)合计值1.5 倍的商品种类
select product_type, sum(sale_price), sum(purchase_price)
from product
group by product_type
having sum(sale_price) > sum(purcha