[英]MySQL select the average timedifference between two timestamp columns for a particular id in a table
[英]Filtering table in MySQL with difference between two timestamp columns
我在MySQL中有一個表,其中包含datetime列open_time
和close_time
。
如何只選擇close_time
比open_time
大至少一分鍾的open_time
?
WHERE TIMESTAMPDIFF(SECOND,close_time,open_time) > 60
更多信息: http : //www.w3resource.com/mysql/date-and-time-functions/mysql-timestampdiff-function.php
您可以使用TIMESTAMPDIFF(unit, datetime_expr1, datetime_expr2)
和類似的東西
select * from MyTab T where TIMESTAMPDIFF(MINUTE,open_date,close_date) > 1
來自文檔
TIMESTAMPDIFF(單元,datetime_expr1,datetime_expr2)
返回datetime_expr2-datetime_expr1,其中datetime_expr1和datetime_expr2是日期或日期時間表達式。 一個表達式可以是日期,另一個可以是日期時間。 在必要時,將日期值視為具有時間部分“ 00:00:00”的日期時間。 結果的單位(整數)由unit參數指定。 單位的合法值與TIMESTAMPADD()函數的說明中列出的值相同。
mysql> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); -> 3
mysql> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); -> -1
mysql> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); -> 128885注意此函數的日期或日期時間參數的順序與使用2個參數調用時TIMESTAMP()函數所使用的順序相反。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.