-- FIND products that are more
-- expensive than Lettuce(id = 3)
SELECT *
FROM products
WHERE unit_price > (
SELECT unit_price
FROM products
WHERE product_id = 3
)
-- (这里面是lettuce的价格)
Output:
---------------------------------------------------------作业----------------------------------------------------------------------------------
--In sql_hr database : Find employees whose earn more than average
SELECT *
FROM employees
WHERE salary > (
SELECT AVG(salary)
FROM employees
)
-- 聚合函数用在SELECT里面