我需要从数据库中检索记录,其中'dateOfTermination'值等于今天的日期。 我使用了以下查询,但它不会显示任何结果。
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
只有在查询如下时才会有效。
select * from user
where CRM_Status='pending' and dateOfTermination = DATE_ADD(CURDATE(), INTERVAL 1 DAY)
是否因日期格式存在问题?
答案 0 :(得分:0)
我的猜测是dateOfTermination
有一个时间组件。试试这个:
select u.*
from user u
where u.CRM_Status = 'pending' and
u.dateOfTermination >= CURDATE() AND
u.dateOfTermination < DATE_ADD(CURDATE(), INTERVAL 1 DAY);
您也可以将其表达为:
select u.*
from user u
where u.CRM_Status = 'pending' and
DATE(u.dateOfTermination) = DATE_ADD(CURDATE(), INTERVAL 1 DAY);
实际上,语义略有不同 - 但目前还不清楚你真正想要的是什么。第一个版本“更好”,因为它可以更好地利用索引来提高性能。
答案 1 :(得分:0)
您可以使用MySQL DATE_FORMAT function获取没有时间组件的日期,然后进行比较。因此查询应如下所示:
SELECT * FROM user
WHERE CRM_Status='pending' AND
DATE_FORMAT(dateOfTermination,'%d-%m-%Y')=DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL 1 DAY),'%d-%m-%Y');
答案 2 :(得分:0)
假设时间问题。为什么不保持简单?
从用户中选择* CRM_Status ='待定'的位置 和cast(dateOfTermination as date)= cast(GETDATE()as DATE)