https://leetcode.cn/study-plan/sql/?progress=xhqm4sjh
# Write your MySQL query statement below
select name,population,area
from World
where area>=3000000 or population>=25000000;
# Write your MySQL query statement below
select name,population,area
from World
where area>=3000000
union
select name,population,area
from World
where population>=25000000;
# Write your MySQL query statement below
select product_id
from Products
where low_fats='Y' and recyclable='Y';
# Write your MySQL query statement below
select name
from customer
where referee_id<>2 or referee_id is NULL;
# Write your MySQL query statement below
select Name Customers
from Customers
where Customers.Id not in(select CustomerIdfrom Orders
);
SQL中IF函数的使用:
IF(expr1,expr2,expr3)
# Write your MySQL query statement below
select employee_id,if(employee_id%2=1 and name not like 'M%',salary,0) bonus
from Employees
order by employee_id;
case when的使用方法:
case 列名when 条件值1 then 选项1when 条件值2 then 选项2.......else 默认值 end
# Write your MySQL query statement below
update Salary
set sex=case sexwhen 'f' then 'm'else 'f' end
;
# Write your MySQL query statement below
update Salary
set sex=case when sex='f'then 'm'else 'f' end
;
# Please write a DELETE statement and DO NOT write a SELECT statement.
# Write your MySQL query statement below
delete p1
from Person p1,Person p2
where p1.email=p2.email and p1.id>p2.id;