SQL Server 中的区别
我正在执行以下查询,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Distinct
应用于所有列,而不是紧随Distinct
之后的列。如果您的
cr_id
有多个不同的ca_email
,您将看到它们全部。如果您不希望这样,则必须制定一条规则来决定必须保留重复项中的哪些记录。
Distinct
is applied to all columns, not the one which is immediately afterDistinct
.If you have several different
ca_email
for acr_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.