
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 · 238 阅读 · 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 · 273 阅读 · 0 评论 -
596.超过5名学生的课
解析select class from coursesgroup by class having count( distinct student) >= 5;之前直接考虑的是,虽然结果相同但是跟题目不符,注意“学生在每个课中不应被重复计算”select class from coursesgroup by class having count( c...原创 2018-10-19 16:52:12 · 254 阅读 · 0 评论 -
183.从不订购的顾客
解析select c.Name as Customers from Customers as c left join Orders as oon c.id = o.CustomerIdwhere o.CustomerId is null; 通过select 查询 Name 并 as Customers左外连接查询当 CustomerId为 null;...原创 2018-10-19 12:17:24 · 241 阅读 · 0 评论 -
181.超过经理收入的员工
解析select a.Name as Employee from Employee as a, Employee as bwhere a.ManagerId = b.Id && a.Salary > b.Salary把Employ看作2个表,a为员工表,b为经理表,且给员工也默认设置有ManagerId通过select查询 Name 并且 as为 Empl...原创 2018-10-19 11:07:02 · 243 阅读 · 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.youkuaiyun.com/u012999796/article/details/6223...原创 2018-10-19 10:49:39 · 232 阅读 · 0 评论 -
620.有趣的电影
解析select id, movie, description, rating from cinemawhere id%2=1 && description != "boring"order by rating DESC通过select 查询根据条件 where id%2=1(单数) && description != "boring"在通...原创 2018-10-19 10:41:45 · 206 阅读 · 0 评论 -
627.交换工资
解析update salary set sex = if(sex="m","f","m");通过使用update更新数据UPDATE table_nameSET column1=value1,column2=value2,...WHERE some_column=some_value;再使用ifif(column = expr1 , expr2 , expr3)如果e...原创 2018-10-19 10:29:56 · 223 阅读 · 0 评论 -
182.查找重复的电子邮件
解析select Email from Persongroup by Emailhaving count(Email)>1;通过select查询,使用group by进行分组,再用用 having count(字段)> 2 进行查询。注意:group by 在having前 group by 在where 后...原创 2018-10-19 09:38:35 · 641 阅读 · 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 · 125 阅读 · 0 评论