mysql 仅选择下周数据
我的数据库中有一个日期字段,即 film_release_date。
那么什么是 mysql 查询从表中获取下周的数据。
我运行此查询,但它无法正常工作。
SELECT
*,
DATE_FORMAT(film_release_date,'%e-%b-%Y') AS release_date
FROM gf_film
WHERE
MONTH(film_release_date)=MONTH(CURRENT_DATE)
AND YEAR(film_release_date)=YEAR(CURRENT_DATE)
AND film_release_date>=(CURRENT_DATE)
ORDER BY film_release_date DESC
实际上它是电影网站,我的数据库中有几部电影,所以我需要一个查询来获取下周的每部电影,这意味着下周发布的电影意味着下周五。如果我今天运行这个,即 13 那么它会显示 15 之间的所有电影到 22,如果在 15 到 22 之间运行,那么它会显示从 22 到 29 的数据
I have a date field in my database i.e film_release_date.
So what is mysql query to fetch the next week data from table.
I run this query but its not working properlly.
SELECT
*,
DATE_FORMAT(film_release_date,'%e-%b-%Y') AS release_date
FROM gf_film
WHERE
MONTH(film_release_date)=MONTH(CURRENT_DATE)
AND YEAR(film_release_date)=YEAR(CURRENT_DATE)
AND film_release_date>=(CURRENT_DATE)
ORDER BY film_release_date DESC
Actually its for movie website i have several movies in my database so i need a query which fetch every next week movie that means movies that will release in next week means next friday.If i run this today i.e 13 then it shows all movies between 15 to 22 and if run this between 15 to 22 then it shows data from 22 to 29
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要获取下周的数据,您可以简单地应用以下逻辑:
参考
to get next week data you can simple apply below logic :
REFERENCE
有点晚了,但没有一个答案能正常工作。您可以使用yearweek 函数来获取一年中的第几周。这样你就得到了 now(本周)的周数或者 now() + 间隔 7 天得到下周。示例:
本周
下周
Little late, but none of the answers works properly. You can use yearweek function to get week number of the year. So you get the week number of now (this week) or now() + interval 7 day to get next week. Examples:
THIS WEEK
NEXT WEEK