我正在执行以下查询,
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),101)) order by a.cr_id
解决方法
Distinct应用于所有列,而不是紧接在Distinct之后的列.
如果你有一个cr_id的几个不同的ca_email,你会看到它们.
如果您不想这样做,则必须提出一条规则来确定重复项中的哪条记录必须保留.