来源:力扣(LeetCode)

1.编写一个 SQL 查询来实现分数排名。如果两个分数相同,则两个分数排名(Rank)相同。请注意,平分后的下一个名次应该是下一个连续的整数值。换句话说,名次之间不应该有“间隔”。例如,根据给定的 Scores 表,你的查询应该返回(按分数从高到低排列):

select a.Score as score,if(a.Score,0,(select count(b.Score)+1 from Scores b where b.score >a.Score)) as Rank from Scores a order by Score Desc;

2.编写一个 SQL 查询,查找所有至少连续出现三次的数字

select disctinct l1.num  as ConsecutiveNums from logs l1, logs l2, logs l3 where l1.ld=l2.ld-1 and l2.id=l3.id-1 and l1.num=l2.num and l2.num-l3.num

3.编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱。

select distinct a.Email  from Person a ,Person b where a.Email=b.Email and a.id !=b.id

4.某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。

select customers.name as 'Customers'
from customers
where customers.id not in ( select customerid from orders )

5

.SQL答题笔记

SELECT
    Department.name AS 'Department',
    Employee.name AS 'Employee',
    Salary
FROM
    Employee
        JOIN
    Department ON Employee.DepartmentId = Department.Id
WHERE
    (Employee.DepartmentId , Salary) IN
    (   SELECT
            DepartmentId, MAX(Salary)
        FROM
            Employee
        GROUP BY DepartmentId
    )

6.

相关文章:

  • 2021-06-09
  • 2021-07-22
  • 2021-06-02
  • 2021-08-13
  • 2021-12-19
  • 2021-09-26
  • 2021-07-19
  • 2021-08-17
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2021-06-29
  • 2021-10-19
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
相关资源
相似解决方案