确定日期范围内的天数
我对Mysql和真诚的道歉是非常陌生的,因为他们努力为这个问题找到正确的方法。
我有一个包含事件时间表时间的表:
Event_ID 1将在03-04-2022至03-12-2022的每个星期一在每个星期一运行在日期范围之间的每个event_id。
I am very much new to the mysql and sincere apologies as struggling to find the right approach for the question.
I have a table which is containing the events schedule time:
Event_id 1 will be running on every Monday in between 03-04-2022 to 03-12-2022.I need to find the total run count of the each Event_id in between a date range.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在开始日期和结束日期之间找到一天。
例如,event_id = 1的开始日期和结束日期之间有多少个星期一,依此类推。
在问题中,start_date和end_date的event_id = 4不正确,因为start_date> end_date。
另外,evnet_id的日名= 4都有一个拼写错误。
解决数据问题后,用于获取结果的查询是
-db fiddle 。
递归查询示例来自在这里。
样本输出
查询的另一个变体 -
You need to find number of day between start and end date.
E.g. how many Monday between start and end date for event_id=1 and so on.
In the question start_date and end_date for event_id=4 are not correct as start_date > end_date.
Also, there is a spelling mistake in day name for evnet_id=4.
The query used for getting the result, after fixing data issues is -
DB fiddle here.
Recursive query example help from here.
Sample output -
Another variant of the query -
首先以日期格式存储日期:
03-04-2022
应以> 2022-04-03
(假设您的格式是每天的年度)存储。并将其存储到声明为日期
的列中,而不是varchar
。然后,您可以使用
netatediff()
函数来获得差异。Start by storing dates in date format:
03-04-2022
should be stored as2022-04-03
(assuming that your format is day-month-year). And store into a column declared to beDATE
, notVARCHAR
.Then you have the ability to use the
DATEDIFF()
function to get differences.