我希望用户可以在本周之前看到他们上传的图片。
这个对吗?
"SELECT *
FROM images
WHERE userid = '$userid'
AND uploadeddate >= DATEPART(week, uploadeddate) = DATEPART(week, GETDATE())
ORDER BY uploadeddate DESC";
我收到错误。谢谢您的帮助。
我希望用户可以在本周之前看到他们上传的图片。
这个对吗?
"SELECT *
FROM images
WHERE userid = '$userid'
AND uploadeddate >= DATEPART(week, uploadeddate) = DATEPART(week, GETDATE())
ORDER BY uploadeddate DESC";
我收到错误。谢谢您的帮助。
SELECT *
FROM images
WHERE userid = $userid
AND uploadeddate >= CURDATE() - INTERVAL WEEKDAY(day) DAY
AND uploadeddate < CURDATE() - INTERVAL WEEKDAY(day) DAY + INTERVAL 7 DAY
为此创建一个索引以(userid, uploadeddate)
使其快速工作。
以下查询将返回本周的记录。在SELECT
.
如果您使用的是 SQL Server:
SELECT ... WHERE DATEPART(week, uploadeddate) = DATEPART(week, GETDATE())
如果您使用的是 MySQL:
SELECT ... WHERE WEEK(uploadeddate) = WEEK(CURDATE())