MySQL:为每个日期选择不同的名称?

发布于 2024-07-23 07:50:45 字数 291 浏览 4 评论 0原文

假设我想选择具有日期范围或 date_feild > 的行 2009-06-01 && 日期字段 < 2009年7月1日。 我想选择名字字段和姓氏字段,但我只希望相同的名字 (F+L) 每个日期显示一次。 因此,只要日期不同,同一个名字就可以多次出现; 但如果这些名字是在同一天,则不会。 这有道理吗? 我们正在尝试跟踪一段时间内收到的查询数量,但如果同一用户在同一天进行了多次查询,我们希望将其计为 1。

我什至还没有开始对此进行编程,所以我持开放态度对所有建议。

谢谢!

Say I want to select rows with a date range or date_feild > 2009-06-01 && date_field < 2009-07-01. and I want to select the first_name_field and last_name_field but I only want the same name (F+L) to show up once per date. So the same name can show up, multiple times as long as their dates are different; but not if the names are on the same date. Does that makes sense? we are trying to track how many inquiries we got over a time period, but if the same user made multiple inquiries on the same day we want to count that as just 1.

I haven't even starting to program this yet so I am open to all suggestions.

Thanks!

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

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

发布评论

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

评论(3

笑饮青盏花 2024-07-30 07:50:45

使用 GROUP BY

SELECT date,name FROM table GROUP BY date,name

use GROUP BY

SELECT date,name FROM table GROUP BY date,name
痴意少年 2024-07-30 07:50:45

不知道在 mySQL 中,但在 SQL Server 中你可以使用 COUNT DISTINCT。

SELECT
    date_field,
    COUNT(DISTINCT first_name + last_name)
FROM
    YourTable
GROUP BY
    date_field

Don't know in mySQL but in SQL Server you can use COUNT DISTINCT.

SELECT
    date_field,
    COUNT(DISTINCT first_name + last_name)
FROM
    YourTable
GROUP BY
    date_field
勿忘初心 2024-07-30 07:50:45

答案就在你的问题中:

select distinct date, concat(first_name, ' ', last_name) from table

The answer is inside your question:

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