[英]MySQL - How to get the difference of all the rows in a column within a specific “id”?
[英]Get all rows with specific time difference
你好,我有一個這樣的表:
|user_name|pw|register_date|last_time_entered
我想獲取last_seen_date-register_date <7的所有行
我不知道如何寫這個查詢,我想到了這樣的事情
SELECT * FROM workoutlog_1.personal
WHERE DATEDIFF(day, workoutlog_1.personal.register_date, workoutlog_1.personal.last_time_entered) < 7;
但是我得到這個錯誤:
Error Code: 1582. Incorrect parameter count in the call to native function 'DATEDIFF'
感謝您的幫助。
您的錯誤代碼似乎來自mysql。
使用mysql, datediff僅需要2個參數(不需要day
)
我認為在(確實)舊版本中,它使用了3個參數,現在僅對2個有效,並且將返回幾天。
如果您必須與另一個單位(例如小時)一起工作,則可以使用TIMESTAMPDIFF
MySql的DATEDIFF與SqlServers DATEDIFF的不同之處在於,它僅接受2個日期參數,並以天為單位返回差值。 既然您仍然想要幾天,則只需刪除day
參數,即
SELECT * FROM workoutlog_1.personal
WHERE DATEDIFF(workoutlog_1.personal.register_date,
workoutlog_1.personal.last_time_entered) < 7;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.