MYSQL 比前一天高的溫度

2021-09-30 16:34:15 字數 723 閱讀 6739

給定乙個weather表,編寫乙個 sql 查詢,來查詢與之前(昨天的)日期相比溫度更高的所有日期的 id。

例如,根據上述給定的weather**,返回如下 id:

解法一:使用to_days()。to_days(date)

select w1.id from weather w1,weather w2 

where w1.temperature>w2.temperature and to_days(w1.recorddate)-1=to_days(w2.recorddate)

解法二:使用date_add()函式。date_add(date,interval expr type)

select w1.id from weather w1 left join weather w2 on w1.temperature>w2.temperature 

where (w1.recorddate)=date_add(w2.recorddate,interval 1 day);

mysql 日期(前一天(月,年),後一)

1,now 返回當前日期和時間 mysql select now now 2015 03 18 22 45 17 1 row in set 0.00 sec 2.curdate 返回當前日期 mysql select curdate curdate 2015 03 18 1 row in set 0...

mysql獲取當前時間,前一天,後一天

負責的專案中,使用的是mysql資料庫,頁面上要顯示當天所註冊人數的數量,獲取當前的年月日,我使用的是 curdate 錯誤的sql語句 eg select count from user where registerdate curdate and registerdate curdate 1 雖...

mysql獲取當前時間,前一天,後一天

原文 負責的專案中,使用的是mysql資料庫,頁面上要顯示當天所註冊人數的數量,獲取當前的年月日,我使用的是 curdate 錯誤的sql語句 eg select count from user where registerdate curdate and registerdate curdate ...