MYSQL 本周选择 [英] MYSQL Select By This Week
本文介绍了MYSQL 本周选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望用户可以在本周之前看到他们上传的图片.
I would like to have user can see their uploaded images by this week.
这是正确的吗?
"SELECT *
FROM images
WHERE userid = '$userid'
AND uploadeddate >= DATEPART(week, uploadeddate) = DATEPART(week, GETDATE())
ORDER BY uploadeddate DESC";
我遇到了错误.感谢您的帮助.
I am getting error. Thanks for the help.
推荐答案
SELECT *
FROM images
WHERE userid = $userid
AND uploadeddate >= CURDATE() - INTERVAL WEEKDAY(day) DAY
AND uploadeddate < CURDATE() - INTERVAL WEEKDAY(day) DAY + INTERVAL 7 DAY
在 (userid, Uploaddate)
上创建一个索引以使其快速工作.
Create an index on (userid, uploadeddate)
for this to work fast.
这篇关于MYSQL 本周选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文