第2章练习题-SQL基础教程

2.1 编写一条 SQL 语句,从 Product(商品)表中选取出“登记日期(regist_
date)在 2009 年 4 月 28 日之后”的商品。查询结果要包含 product_
name 和 regist_date 两列

select product_name,regist_date
from product
where regist_date>'2009-04-28';

2.2 请说出对 Product 表执行如下 3 条 SELECT 语句时的返回结果

select *
from product
where purchase_price=null;

select *
from product
where purchase_price<>null;

select *
from product
where purchase_price>null;

一条记录也取不出来

2.3 代码清单 2-22(2-2 节)中的 SELECT 语句能够从 Product 表中取出“销
售单价(sale_price)比进货单价(purchase_price)高出 500
日元以上”的商品。请写出两条可以得到相同结果的 SELECT 语句。执行
结果如下所示

第2章练习题-SQL基础教程

select product_name,sale_price,purchase_price
from product
where sale_price>=purchase_price+500;
select product_name,sale_price,purchase_price
from product
where sale_price-500>=purchase_price;

2.4 请写出一条 SELECT 语句,从 Product 表中选取出满足“销售单价打九
折之后利润高于 100 日元的办公用品和厨房用具”条件的记录。查询结果
要包括 product_name 列、product_type 列以及销售单价打九折之
后的利润(别名设定为 profit)

select product_name,product_type,sale_price*0.9-purchase_price profit
from product
where sale_price*0.9-purchase_price>100 
and
(product_type='办公用品' or product_type='厨房用具');