更新所有贷款 WHERE user_id=?在 DATEDIFF() >0 的情况下。错误 1242 和 1093
Update For all loans WHERE user_id=? in CASE when DATEDIFF() >0. Error 1242 and 1093
我有这个问题
Update loans set fine = case
when DATEDIFF((
(SELECT * from (SELECT loans.due_date FROM loans where users_id = 1) AS l1))
,DATE(NOW())) > 0 THEN 1
ELSE fine
END
WHERE users_id =1;
来自table
+-------------+
| Field |
+-------------+
| users_id |
| books_isbn |
| aquire_date |
| due_date |
| fine |
+-------------+
它适用于只有一个 'loans' 的用户,但我不知道如何让它适用于一个用户的多个 'loans'。 =(
我希望查询看起来像这样:
Update loans l
set fine = 1
where users_id = 1 and l.due_date < curdate();
在没有示例数据和预期结果的情况下找出确切的逻辑有点棘手。
我有这个问题
Update loans set fine = case
when DATEDIFF((
(SELECT * from (SELECT loans.due_date FROM loans where users_id = 1) AS l1))
,DATE(NOW())) > 0 THEN 1
ELSE fine
END
WHERE users_id =1;
来自table
+-------------+
| Field |
+-------------+
| users_id |
| books_isbn |
| aquire_date |
| due_date |
| fine |
+-------------+
它适用于只有一个 'loans' 的用户,但我不知道如何让它适用于一个用户的多个 'loans'。 =(
我希望查询看起来像这样:
Update loans l
set fine = 1
where users_id = 1 and l.due_date < curdate();
在没有示例数据和预期结果的情况下找出确切的逻辑有点棘手。