参考答案:task02

2.1

SELECT product_name, regist_date
  FROM product
 WHERE regist_date > '2009-04-28';

2.2

/*
  下面是问题的SELECT语句
*/
-- ①
SELECT *
      FROM product
     WHERE purchase_price = NULL;

-- ②
SELECT *
      FROM product
     WHERE purchase_price <> NULL;

-- ③
SELECT *
      FROM product
     WHERE product_name > NULL;

2.3

-- SELECT语句①
SELECT product_name, sale_price, purchase_price
  FROM product
 WHERE sale_price >= purchase_price + 500;


-- SELECT语句②
SELECT product_name, sale_price, purchase_price
  FROM product
 WHERE sale_price - 500 >= purchase_price;

2.4

SELECT product_name, product_type,
       sale_price * 0.9 - purchase_price AS profit
  FROM product
 WHERE sale_price * 0.9 - purchase_price > 100
   AND (   product_type = '办公用品'
        OR product_type = '厨房用具');

2.5

错误 ①
字符型字段 product_name 不可以进行 SUM 聚合
错误 ②
WHERE 语句应该书写在 GROUP BY 语句之前( FROM 语句之后)
错误 ③
GROUP BY 字段(product_type)与 SELECT 字段不同(product_id

2.6

SELECT product_type, SUM(sale_price), SUM(purchase_price)
  FROM product
 GROUP BY product_type
HAVING SUM(sale_price) > SUM(purchase_price) * 1.5;

2.7

SELECT *
  FROM product
 ORDER BY regist_date DESC, sale_price;