1

我有这个查询

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        |
+-------------+

它适用于只有一个“贷款”的用户,但我不知道如何使其适用于一个用户的多个“贷款”。=(

4

1 回答 1

1

我希望查询看起来像这样:

Update loans l
    set fine = 1
    where users_id = 1 and l.due_date < curdate();

在没有样本数据和期望结果的情况下找出确切的逻辑有点棘手。

于 2017-09-17T03:32:44.087 回答