1.编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary)
select (select distinct Salary from Employee order by Salary desc limit 1 offset 1) as SecondHighestSalary;
2.给定一个 Weather 表,编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 Id
select A.Id from Weather A
inner join Weather B
on A.Temperature > B.Temperature
and datediff(A.RecordDate,B.RecordDate)=1
SELECT w1.Id FROM Weather w1, Weather w2
WHERE w1.Temperature > w2.Temperature AND TO_DAYS(w1.RecordDate)=TO_DAYS(w2.RecordDate) + 1;
3.您需要编写一个 SQL查询,找出所有影片描述为非 boring (不无聊) 的并且 id 为奇数 的影片,结果请按等级 rating 排列
select * from cinema
where description not like'boring'
and id&1
order by rating
select A.Name from Employee A
inner join Employee B
on A.ManagerId=B.Id
where A.Salary>B.Salary
5.编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱。
select distinct A.Email from Person A, Person B
where A.Email=B.Email and A.Id <> B.Id
select Email from Person group by Email having count(Email)>1
6.某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。
select Name as Customers
from Customers
where Id not in(
select C.Id
from Customers as C, Orders as O
where C.Id = O.CustomerId)
7.编写一个 SQL 查询,满足条件:无论 person 是否有地址信息,都需要基于上述两表提供 person 的以下信息:
select Person.FirstName,Person. LastName, Address.City, Address.State from Person
left join Address
on Person.PersonId=Address.PersonId
8.有一个courses 表 ,有: student (学生) 和 class (课程)。 请列出所有超过或等于5名学生的课
select class from courses
group by class
having count(distinct student) >= 5
9.如果一个国家的面积超过300万平方公里,或者人口超过2500万,那么这个国家就是大国家。
select name,population,area from World
where area>3000000 or population>25000000