第六章 练习题

2018-07-24  本文已影响0人  susupp

6.1

SELECT
    product_name,
    purchase_price
FROM
    Product
WHERE
    purchase_price NOT IN (500, 2800, 5000);

返回4条结果

SELECT
    product_name,
    purchase_price
FROM
    Product
WHERE
    purchase_price NOT IN (500, 2800, 5000, NULL);

不返回任何结果

6.2

SELECT
    sum(
        CASE
        WHEN sale_price <= 1000 THEN
            1
        ELSE
            0
        END
    ) AS low_price,
    sum(
        CASE
        WHEN sale_price BETWEEN 1001
        AND 3000 THEN
            1
        ELSE
            0
        END
    ) AS mid_price,
    sum(
        CASE
        WHEN sale_price >= 3001 THEN
            1
        ELSE
            0
        END
    ) AS high_price
FROM
    product;

上一篇下一篇

猜你喜欢

热点阅读