[英]Select the rows where Balance is greater than 10000 and expiration date is less than 2 days from today
[英]Retrieve rows with joining date less than 15 days from today
Mysql查詢是
SELECT
userid as uid,
CONCAT( firstname, ' ', lastname ) AS name,
profileimage,
joining_date,
role as designation
FROM pr_users_details
INNER JOIN pr_users ON pr_users.id = pr_users_details.userid
LEFT JOIN pr_userroles ON pr_userroles.id = pr_users.userroleid
WHERE joining_date > DATE_SUB( NOW()-1 , INTERVAL 15 DAY )
ORDER BY pr_users_details.id DESC
我得到了這些一年前的結果。 我想顯示新員工,即今天的日期 - 15 天。 我是不是錯過了什么。
您應該將日期/時間存儲為日期時間,而不是字符串。 為了進行比較,您需要將值轉換為字符串:
WHERE STR_TO_DATE(joining_date, '%d-%m-%Y') > DATE_SUB( NOW()-1 , INTERVAL 15 DAY )
但是,您應該修復數據:
update ? -- whatever the table is
set joining_date = STR_TO_DATE(joining_date, '%d-%m-%Y'); -- this will convert the date to a canonical format
alter table t alter column joining_date date;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.