这次学习看的只有两节,可是实际的内容是非常多的,把内连接外连接分开学习了,没有一次学习完,各自花了2个多小时。无论是在群里还是在课程中都有提到连接是SQL中最为中的知识点了。
梳理下对内连接的学习,就是先掌握内连接的基本语法,之后就是围绕基本语法和前面所学的进行拓展,比如和GROUP BY还有WHERE,再者学到最后就能体会到内连接相比于关联子查询的好处,真的非常有用。
习题1
SELECT *
FROM Product
WHERE sale_price > 500
UNION
SELECT *
FROM Product
WHERE sale_price >500;
习题2
SELECT *
FROM Product
WHERE product_id NOT IN (SELECT product_id FROM Product2)
UNION
SELECT *
FROM Product2
WHERE product_id NOT IN (SELECT product_id FROM Product)
习题3
不会
习题4
不会
习题5
SELECT SP.shop_id
,SP.shop_name
,MAX(P.sale_price) AS max_price
FROM shopproduct AS SP
INNER JOIN product AS P
ON SP.product_id = P.product_id
GROUP BY SP.shop_id,SP.shop_name