MySQL 计数(不同(电子邮件)和按日期分组(条目日期)

发布于 2024-11-29 11:25:46 字数 274 浏览 1 评论 0原文

在获取唯一记录总数和按日期分组方面遇到了一些麻烦。最终结果是我每天都会收到总计,但它没有使用基于不同功能的唯一电子邮件。这是我的查询...

SELECT count(distinct(emailaddress)), DATE(EntryDate)
FROM tblentries
group by   DATE(EntryDate)
ORDER BY DATE(EntryDate) desc

结果最终没有对每天的计数进行重复数据删除。想法?

谢谢!

Having a bit of trouble with getting total unique records and grouping by date. The end result is I am getting totals per day but it is not using unique emails based on the distinct function. Here is my query...

SELECT count(distinct(emailaddress)), DATE(EntryDate)
FROM tblentries
group by   DATE(EntryDate)
ORDER BY DATE(EntryDate) desc

The results end up not de-duping the count for each day. Thoughts?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十年不长 2024-12-06 11:25:46

根据对话,我相信您正在寻找的是每天不同的从未见过的电子邮件地址的数量:

SELECT
    DATE(t.EntryDate) as RecordDate,
    COUNT(DISTINCT t.emailaddress) as NewEmailAddresses
FROM
    tblentries t
WHERE
    NOT EXISTS(
        SELECT 1
        FROM tblentries t2
        WHERE
            t2.emailaddress = t.emailaddress
            AND DATE(t2.EntryDate) < DATE(t.EntryDate)
    )
GROUP BY
    DATE(t.EntryDate)
ORDER BY
    DATE(t.EntryDate) ASC;

这是我的想法,所以它可能不正确,而且会很慢,但是我认为这是正确的方向。顺便说一句,如果您计划定期运行此操作,则电子邮件地址索引将是一个好主意。

让我知道这是否有效。

Based on the conversation, I believe what you are looking for is the number of distinct never-before-seen email addresses per day:

SELECT
    DATE(t.EntryDate) as RecordDate,
    COUNT(DISTINCT t.emailaddress) as NewEmailAddresses
FROM
    tblentries t
WHERE
    NOT EXISTS(
        SELECT 1
        FROM tblentries t2
        WHERE
            t2.emailaddress = t.emailaddress
            AND DATE(t2.EntryDate) < DATE(t.EntryDate)
    )
GROUP BY
    DATE(t.EntryDate)
ORDER BY
    DATE(t.EntryDate) ASC;

This is off the top of my head, so it may not be right, and it will be slow, but I think this is in the right direction. On a side note, if you plan on running this regularly, an index on emailaddress would be a good idea.

Let me know if this works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文