leetcode数据库
SneakyRogue
这个作者很懒,什么都没留下…
展开
-
595.大的国家
595.大的国家 创建表用到的sql语句 -- ---------------------------- -- Table structure for `world` -- ---------------------------- DROP TABLE IF EXISTS `world`; CREATE TABLE `world` ( `name`varchar(255) DEFAU...原创 2018-10-19 09:28:37 · 222 阅读 · 0 评论 -
176.第二高的薪水
解析 select max(Salary) as SecondHighestSalary from Employee where Salary <(select max(Salary) from Employee ) 最大查询 select max(column) from table 第二大在 最大的基础上添加 where条件 select max(column) fr...原创 2018-10-19 20:49:37 · 256 阅读 · 0 评论 -
596.超过5名学生的课
解析 select class from courses group by class having count( distinct student) >= 5; 之前直接考虑的是,虽然结果相同但是跟题目不符,注意“学生在每个课中不应被重复计算” select class from courses group by class having count( c...原创 2018-10-19 16:52:12 · 233 阅读 · 0 评论 -
183.从不订购的顾客
解析 select c.Name as Customers from Customers as c left join Orders as o on c.id = o.CustomerId where o.CustomerId is null; 通过select 查询 Name 并 as Customers 左外连接查询 当 CustomerId为 null;...原创 2018-10-19 12:17:24 · 233 阅读 · 0 评论 -
181.超过经理收入的员工
解析 select a.Name as Employee from Employee as a, Employee as b where a.ManagerId = b.Id && a.Salary > b.Salary 把Employ看作2个表,a为员工表,b为经理表,且给员工也默认设置有ManagerId 通过select查询 Name 并且 as为 Empl...原创 2018-10-19 11:07:02 · 226 阅读 · 0 评论 -
175.组合两个表
解析 select a.FirstName, a.LastName, b.City, b.State from Person as a left join Address as b on a.PersonId = b.PersonId 根据题目要求是用左外连接这边可以看一下这个帖子https://blog.csdn.net/u012999796/article/details/6223...原创 2018-10-19 10:49:39 · 214 阅读 · 0 评论 -
620.有趣的电影
解析 select id, movie, description, rating from cinema where id%2=1 && description != "boring" order by rating DESC 通过select 查询 根据条件 where id%2=1(单数) && description != "boring" 在通...原创 2018-10-19 10:41:45 · 184 阅读 · 0 评论 -
627.交换工资
解析 update salary set sex = if(sex="m","f","m"); 通过使用update更新数据 UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value; 再使用if if(column = expr1 , expr2 , expr3)如果e...原创 2018-10-19 10:29:56 · 210 阅读 · 0 评论 -
182.查找重复的电子邮件
解析 select Email from Person group by Email having count(Email)>1; 通过select查询,使用group by进行分组, 再用用 having count(字段)> 2 进行查询。 注意:group by 在having前 group by 在where 后...原创 2018-10-19 09:38:35 · 618 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
Given a string, find the length of thelongest substringwithout repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. 此题需要求出最长的不重复...原创 2019-04-16 22:39:53 · 114 阅读 · 0 评论