在MySQL中的两个日期之间计数重复记录
我正在尝试计算两个日期之间的重复记录数量。
这是一些数据。
REC_DATE | NAME | MED | 指示 |
---|---|---|---|
2022-06-22 | 博客 | 酰甲 | 氨基甲电脑每天四次 |
2022-06-21 | MR | 帕 | MR Blog Asprin Asprion Asprion Asprion Asprion Asporin Asporin四次片剂每天四次 |
2022-04--04-04--04--04--04- | MR Blog Blogs | ParaceTamol | One ParaceTamol One Tablet Tablet Tablet Tablet Tablet Table Table Table每天 |
2022-06-20 19 | 先生博客 | 铁 | 每天一次 |
一片2022-03-09 | MR博客 | Salbutamol | One Puff时需要在需要的 |
2022-02-08 | MR Blog Blog Blogs | ParaceTamol | 两次片剂每天四次 |
2022-02-02 2022-02 | MR Blog Blogs | ParaceTamol | 每天两片两片2022222222222222222222222222年 |
。 -02-04 | MR Blogs | paraceTamol | 每天四次一台平板电脑 |
,到目前为止,我已经设法解决了。这计算了重复的确切匹配的次数。
SELECT
rec_date,
name,
med,
directions
COUNT(*) as number
FROM
datatable da
WHERE
da.rec_date>={d '2022-06-20'}
AND da.rec_date<={d '2022-06-22'}
GROUP BY med, name
HAVING COUNT(*)>2
这将导致1重复,因为它们是相同的。
rec_date | name | Med | 指示 |
---|---|---|---|
2022-06-22 | MR Blog Blogs | ParaceTamol | 每天四次 |
2022-06-21 | MR Blog Blogs | ParaceTamol | 每天四次平板电脑 |
,但是,如果我更改日期的日期会
da.rec_date>={d '2022-01-20'}
AND da.rec_date<={d '2022-06-22'}
导致2个重复关系,正确吗?
我有什么办法可以每两个日历获得数量的重复项?
如果将日期范围扩展到一年,我将获得高度的重复计数,但我想知道每两周有多少个复制品。
在SQL中可以吗?
我想到的是计算两个重复条目之间的日期是否在14天内。如果没有,那不是重复的。
否则,我可以将数据导出到Excel文件中,并可能使用枢轴表分解数据?
亲切的问候。
编辑
重复记录的定义将在REC_DATE的14天内使用相同的名称,MED和指示。
I'm trying to COUNT the number of duplicate records between two dates.
Here is some data.
rec_date | name | med | directions |
---|---|---|---|
2022-06-22 | mr blogs | paracetamol | ONE tablet FOUR times a day |
2022-06-21 | mr blogs | paracetamol | ONE tablet FOUR times a day |
2022-06-20 | mr blogs | aspirin | ONE tablet FOUR times a day |
2022-04-19 | mr blogs | iron | ONE tablet ONCE a day |
2022-03-09 | mr blogs | salbutamol | ONE puff when required |
2022-02-08 | mr blogs | paracetamol | TWO tablets FOUR times a day |
2022-02-06 | mr blogs | paracetamol | TWO tablets FOUR times a day |
2022-02-04 | mr blogs | paracetamol | ONE tablet FOUR times a day |
So far, I've managed to work this out; this counts how many times an exact match is duplicated.
SELECT
rec_date,
name,
med,
directions
COUNT(*) as number
FROM
datatable da
WHERE
da.rec_date>={d '2022-06-20'}
AND da.rec_date<={d '2022-06-22'}
GROUP BY med, name
HAVING COUNT(*)>2
This would result 1 duplicate as these are the same.
rec_date | name | med | directions |
---|---|---|---|
2022-06-22 | mr blogs | paracetamol | ONE tablet FOUR times a day |
2022-06-21 | mr blogs | paracetamol | ONE tablet FOUR times a day |
However, If I alter the dates to be
da.rec_date>={d '2022-01-20'}
AND da.rec_date<={d '2022-06-22'}
This results in 2 duplicates, correct?
Is there any way I am able to get a quantity of duplicates PER calendar fortnight?
If I extend the date ranges to a year, I'm going to get a high count of duplcates, but I would like to know how many duplicates every TWO weeks.
Is that possible in SQL?
I thought about maybe counting if the dates between two duplicate entries are within 14 days. If not then it's not a duplicate.
Otherwise I can export the data into an excel file and maybe breakdown the data using pivot tables?
Kind regards.
EDIT
Definition of duplicate record would be the same name, med and directions within 14 days of rec_date.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论