SQL Server 中的区别

发布于 2024-12-16 18:19:08 字数 601 浏览 0 评论 0原文

我正在执行以下查询,

Select distinct
  a.cr_id,
  Case 
    When ca.ca_vote = 'Approve' and ca.ca_title='MANAGER' Then ca.ca_email
    When ca.ca_vote = 'Reject' Then ''
    When ca.ca_vote = 'Pending' Then ''
    When ca.ca_vote = 'IN PROCESS' Then ''
  End as ca_email
from
  credit a
  inner join credit_approvals ca on ca.c_id=a.cr_id
where 
  a.cr_cs_date between Convert(varchar(20),'11/16/2011',101) and dateadd(day,1,convert  (varchar(20),'11/16/2011',101))
order by
  a.cr_id

尽管 cr_id 具有 distinct,但它仍然显示重复值。请让我知道如何处理这个问题,以便我能够只显示不同的记录。

I am executing the following query,

Select distinct
  a.cr_id,
  Case 
    When ca.ca_vote = 'Approve' and ca.ca_title='MANAGER' Then ca.ca_email
    When ca.ca_vote = 'Reject' Then ''
    When ca.ca_vote = 'Pending' Then ''
    When ca.ca_vote = 'IN PROCESS' Then ''
  End as ca_email
from
  credit a
  inner join credit_approvals ca on ca.c_id=a.cr_id
where 
  a.cr_cs_date between Convert(varchar(20),'11/16/2011',101) and dateadd(day,1,convert  (varchar(20),'11/16/2011',101))
order by
  a.cr_id

Despite distinct for cr_id, it is still displaying the duplicate values. Please let me know how to handle this, so that I could able to display only distinct records.

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

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

发布评论

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

评论(1

迎风吟唱 2024-12-23 18:19:08

Distinct 应用于所有列,而不是紧随 Distinct 之后的列。

如果您的 cr_id 有多个不同的 ca_email,您将看到它们全部。

如果您不希望这样,则必须制定一条规则来决定必须保留重复项中的哪些记录。

Distinct is applied to all columns, not the one which is immediately after Distinct.

If you have several different ca_email for a cr_id, you will see them all.

If you don't want that, you have to come up with a rule to decide what record among the duplicates must stay.

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