zoukankan      html  css  js  c++  java
  • leetcode数据库sql之Rising Temperature

    leetcode原文引用:

    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 |
    +----+
    我的sql语句如下:

    select t2.id from Weather t1 
    inner join Weather t2 on 
    t1.Temperature < t2.temperature
    and 
    to_days(t1.Date) = to_days(t2.Date)-1

    注意:原来忘了使用to_days函数,导致提交一直说有错误,必须要加上to_days函数!!

  • 相关阅读:
    Mysql自定义函数总结
    MySQL的基本函数
    Mysql存储过程总结
    Mysql触发器总结
    Mysql索引总结(二)
    Mysql索引总结(一)
    Mysql游标使用
    别人的博客,留待后看
    mysql外键约束总结
    mysql视图总结
  • 原文地址:https://www.cnblogs.com/iamconan/p/7383577.html
Copyright © 2011-2022 走看看