计算另一个计数值,但前提是它足够高
我正在尝试提取 2 个数字。第一个是 1 个月内总共有多少医生(dr 表)有超过 10 个答案(答案表),无论日期如何,总共有 75 个答案。另一个数字是相同的,但是在过去 3 个月内而不是 1 个月内。
我使用下面的这个答案来提出这个查询
SELECT D.name,
count(DISTINCT case when A.created > DATE_SUB(NOW(), INTERVAL 1 MONTH) then A.id end) as '1 month',
count(DISTINCT case when A.created > DATE_SUB(NOW(), INTERVAL 3 MONTH) then A.id end) as '1 quarter',
count(DISTINCT A.id) as total
FROM dr D
JOIN answer A ON A.dr_id=D.id AND A.status=3
GROUP BY D.id
:为我提供了所需的原始信息,但我不知道如何通过将它们与 10 和 75 个答案要求进行比较来计算给出的计数。
I'm trying to pull 2 numbers. One is a total of how many doctors (dr table) have more than 10 answers (answers table) from within 1 month and 75 answers total regardless of the date. The other number is the same thing but for within the last 3 months instead of 1 month.
I used this answer answer below to come up with this query:
SELECT D.name,
count(DISTINCT case when A.created > DATE_SUB(NOW(), INTERVAL 1 MONTH) then A.id end) as '1 month',
count(DISTINCT case when A.created > DATE_SUB(NOW(), INTERVAL 3 MONTH) then A.id end) as '1 quarter',
count(DISTINCT A.id) as total
FROM dr D
JOIN answer A ON A.dr_id=D.id AND A.status=3
GROUP BY D.id
This gives me the raw information I need, but I don't know how to count the counts given by comparing them to the 10 and 75 answers requirements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想是这样的:
Something like this, I think:
您可能需要稍微玩一下这个查询,但它应该会为您提供您正在寻找的内容。基本上将您的查询用作派生表,并使用 group by/having 进一步总结它。
You might need to play w/ this query a bit, but it should give you what you're looking for. Basically take your query and use it as a derived table and summarize it further using group by/having.