先从简单开始
思路:对Email列进行count函数计算,依赖于group by(按照不同得邮箱进行分组。这样得话就可以得到一个这样得数据:每个邮箱对应得条数。这样只要求出每个条数>1得邮箱就是我们想要得。)
解答:
select Email
from(
select Email count(Email) as num
from Person
group by Email
) as EmailNum
where num>1;
思路:其实就是求Customers表里面没有在Oders表里面得Id对应得Name。很容易联想到 Not In得用法
解答:
select Name as Customers
from Customers
where Customers.Id not in(
select CustomersId
from Orders
);
太水了,
select name,population,area
from World
where area>3000000 or population>25000000
思路:和第一题其实是一样得。区别在于最后一句话,就是学生不应该被重复进行统计。所以要加个distinct
解答:
select class
from (
select class,count(distince student)
from courses
group by class
) as classnum
where num >= 5
思路:很水,唯一就是奇数id利用mod函数求一下就行
解答
select *
from cinema
where description != 'boring' and mod(id,2)=1
order by rating desc
思路:在我们得sql语句里面使用if函数
update salary
set sex=if(sex='f','m','f');