且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在查询中丢失重复项

更新时间:2022-12-03 07:59:47

您不能在选择不在您的group by子句或聚合函数的一部分的列表。您的查询是仅向我显示一次电子邮件,但每次显示日期 - 这是不可能完成的。


如果您只是寻找电子邮件列表,请从选择列表中删除日期。如果您需要包含日期,则需要考虑要包含的日期。例如,您可以使用Max()聚合函数来包含与每封电子邮件关联的最高(最近)日期。
You cannot include a field in your select list that isn''t in your group by clause or part of an aggregate function. Your query is saying "show me the e-mail only once, but show me every date" - which can''t be done.

If you''re looking for just a list of e-mails, then drop the date from your select list. If you need the date included, you need to think about which date you want included. For example, you could use the Max() aggregate function to include the highest (most recent) date associated with each e-mail.


我认为您需要更清楚地了解您的想法你想做什么。这样你就可以提出一个更有意义的问题,或者更准确地反映你想知道的问题。


我猜你真的不是在寻找一个GROUP通过查询,但你只是想避免任何重复。在这种情况下,您需要select子句的DISTINCT谓词。类似于:

I think you need to get clearer in your mind exactly what you''re trying to do. That way you can ask a question that makes more sense, or more accurately reflects what you want to know.

I''m guessing that you''re not really looking for a GROUP BY query at all, but that you simply want to avoid any duplicates. In that case you need the DISTINCT predicate of the select clause. Something like :

展开 | 选择 | Wrap | 行号


我所拥有的是一次或多次在线购票的买家列表在不同的日期。系统根据电子邮件地址跟踪购买日期。如果同一电子邮件地址在不同日期购买,则会将其作为另一个销售进行跟踪。我现在要从我的数据库中提取的是电子邮件地址,无论他们在不同的日期购买了多少。
What I have is a list of buyers who buy tickets online once or many times on different dates. The system tracks the date of purchase against the email address. If the same email address buys on different days it is tracked as another sale. What I want to extract from my database now is the email address, no matter how many they bought on different dates.