【Leetcode】Rising Temperature
2016-05-16 11:17
288 查看
题目链接:https://leetcode.com/problems/rising-temperature/
题目:
Given a Weather table, write a SQL query to find all dates’ Ids with higher temperature compared to its previous (yesterday’s) dates.
+———+————+——————+
| Id(INT) | Date(DATE) | Temperature(INT) |
+———+————+——————+
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
+———+————+——————+
For example, return the following Ids for the above Weather table:
+—-+
| Id |
+—-+
| 2 |
| 4 |
+—-+
思路:
二表联查
算法:
题目:
Given a Weather table, write a SQL query to find all dates’ Ids with higher temperature compared to its previous (yesterday’s) dates.
+———+————+——————+
| Id(INT) | Date(DATE) | Temperature(INT) |
+———+————+——————+
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
+———+————+——————+
For example, return the following Ids for the above Weather table:
+—-+
| Id |
+—-+
| 2 |
| 4 |
+—-+
思路:
二表联查
算法:
SELECT w1.Id FROM Weather w1 INNER JOIN Weather w2 ON TO_DAYS(w1.Date) = TO_DAYS(w2.Date) + 1 AND w1.Temperature > w2.Temperature
相关文章推荐
- zookeeper初步
- asp.net web 开发登录相关操作的控件LoginName、LoginStatus和LoginView控件使用详解
- 汉诺塔-递归
- 使用linux构建一台路由器
- Ionic开发中注意事项(持续更新)
- Linux国内常用源的介绍和使用(Ubuntu16.04为例)
- ppc64le centos7 安装etcd
- Synchronized
- Spring MVC与Ajax交互实例
- 浅谈 EventBus
- JavaWeb不错的教程01
- 【JDK】:Executor框架
- 进程概述和内存分配
- 非聚集索引查找转非聚集索引扫描
- 知道这20个正则表达式,能让你少写1,000行代码
- iOS FMDB的使用(增,删,改,查,sqlite存取图片)
- 加密解密的一个小测试
- 连接数据库超时设置autoReconnect=true
- android设置webview的适配比例,setInitialScale 方法神奇的功能
- 【Leetcode】 Second Highest Salary