我有这个查询
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;
从表格
+-------------+
| Field |
+-------------+
| users_id |
| books_isbn |
| aquire_date |
| due_date |
| fine |
+-------------+
与用户合作只有一个'贷款',但我不知道如何让它与一个用户的几个“贷款”一起工作。 =(
答案 0 :(得分:1)
我希望查询看起来像这样:
Update loans l
set fine = 1
where users_id = 1 and l.due_date < curdate();
在没有样本数据和期望结果的情况下找出确切的逻辑是有点棘手的。