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 |
+----+

思路:

TO_DAYS(date)可以将日期转换成公元后的天数。

# Write your MySQL query statement below
select w1.Id from Weather as w1, Weather as w2
WHERE TO_DAYS(w1.Date) = TO_DAYS(w2.Date) + 1 and w1.Temperature > w2.Temperature

Leetcode 197. Rising Temperature的更多相关文章

  1. leetcode 197. Rising Temperature sql_Date用法

    https://leetcode.com/problems/rising-temperature/description/ 题目需要选出今天比昨天气温高的ID 用join,默认是inner join需 ...

  2. LeetCode 197. Rising Temperature (上升的温度)

    题目标签: 题目给了我们一个 温度表格,让我们找到 所有温度比之前一天高的,返回id. 建立 Weather w1, Weather w2,找到当w1 的温度 大于 w2 的时候,而且 w1 的日期是 ...

  3. [LeetCode] 197. Rising Temperature_Easy tag: SQL

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  4. [SQL]197. Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  5. 197. Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  6. [LeetCode] Rising Temperature 上升温度

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  7. [SQL]LeetCode197. 上升的温度 | Rising Temperature

    SQL架构 Create table If Not Exists Weather (Id int, RecordDate date, Temperature int) Truncate table W ...

  8. DateBase -- Rising Temperature

    Question: Given a Weather table, write a SQL query to find all dates' Ids with higher temperature co ...

  9. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

随机推荐

  1. 静态NAT、动态NAT

    静态NAT.动态NAT 实验拓扑: 实验目的:熟悉网络地址转换协议 掌握静态NAT 和动态NAT的配置 分析静态NAT 和动态NAT的区别 使用show命令来检查NAT的运行情况 实验要求:按拓扑图来 ...

  2. css position relative obsolution

    层级关系为:<div ——————————— position:relative; 不是最近的祖先定位元素,不是参照物<div—————————-没有设置为定位元素,不是参照物<di ...

  3. mysql链接表,connection string, federated engine

    http://database.51cto.com/art/201011/234561.htm

  4. 重点block

    //  main.m //  block探索 // //  Created by 殷婷婷 on 15-6-6. //  Copyright (c) 2015年 lanou. All rights re ...

  5. RocketMQ源码 — 三、 Producer消息发送过程

    Producer 消息发送 producer start producer启动过程如下图 public void start(final boolean startFactory) throws MQ ...

  6. PAT (Advanced Level) 1061. Dating (20)

    简单模拟. #include<stdio.h> #include<string.h> ],s2[],s3[],s4[]; ][]={"MON ", &quo ...

  7. dotnet webservice处理数据量过大,ajax请求返回500错误解决方案

    ajax请求webservice返回json数据,数据规模过大时ajax请求会得到500的响应,webservice+ajax处理大规模的数据需要在web.config中进行如下配置: <sys ...

  8. opencart配置

    1.安装opencart 2.修改后台目录(慎重,修改后插件安装会出错) Opencart默认的后台是网站/admin这样子,很多人可以猜到这种组合对于正式生产环境很不安全,我们可以把这个admin改 ...

  9. springMVC注解及优化

    1. 新建web project 2. 添加jar 3. 改写web.xml, 注意spring-servlet.xml的名字 <?xml version="1.0" enc ...

  10. openjdk

    apt-get install mercurial hg clone http://hg.openjdk.java.net/jdk8u/jdk8u20/ jdk8u20 ./get_source.sh