跟着AI学sql
1、左连接返回左表全部leftjoin..on....表1Person(PersonId,FirstName,LastName)表2Address(AddressId,PersonId,City,State)查询每个人的姓、名、城市、州没有人的地址也要显示select p.FirstName,p.LastName,a.City,a.State from Person p left join Address a on p.PersonId a.PersonId;2、求第二高薪水表Employee(id,salary)select salary from Employee order by salary desc limit 1 offset 13、超过经理收入的员工表Employee(idnamesalarymanagerId)select e1.name as Employee from Employee e1 join Employee e2 on e1.managerId e2.id where e1.salary e2.salary4、查找重复电子邮箱表Person(idemail)select email from Person group by email where having count(emil)15、从不买东西的客户Customers(id,name),Orders(id,customerId)select name from Customers where id not in (select customerId from Orders) 解法2 select c.name as Customers from Customers c left join Orders o on c.ido.customerId where o.id is null6、超过5名学生的课Courses(studnet,class)select class from Courses group by class having count(distinct student) 5注意where是分组之前过滤having是分组之后过滤先where在groupby先groupby在havingwhere-groupby-having
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2517962.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!