小编典典

选择不同的退货重复

sql

我有以下查询:

SELECT 
DISTINCT (TK.TICKETID),
TK.DESCRIPTION,
TK.CREATIONDATE,
TK.REPORTEDBY,
TK.OWNER,
WF.ASSIGNCODE
FROM ticket TK
INNER JOIN wfassignment WF on WF.OWNERID = TK.TICKETUID
WHERE TK.status not in ('效袝袪袧袨袙袠袣', '袟袗袣袪蝎孝', '袙蝎袩袨袥袧袝袧') AND WF.ASSIGNSTATUS not in ('COMPLETE', 'INACTIVE')
ORDER BY TK.TICKETID;

但是它在TK.TICKETID属性中返回重复项。如果我删除其他属性都可以。例如

TK.TICKETID TK.DESCRIPTION TK.CREATIONDATE  TK.REPORTEDBY  TK.OWNER     WF.ASSIGNCODE
О1013249    Право доступа   02.06.14        CHERNOVDK      SKACHKOVSV   NOVIKOVVA
О1013249    Право доступа   02.06.14        CHERNOVDK      SKACHKOVSV   PRITULADV
О1013249    Право доступа   02.06.14        CHERNOVDK      SKACHKOVSV   SVESHNIKOVAV

Mb我的问题很简单,但我自己无法解决。任何帮助都会很棒。


阅读 158

收藏
2021-05-16

共1个答案

小编典典

试试这个:

SELECT 
TK.TICKETID,
TK.DESCRIPTION,
TK.CREATIONDATE,
TK.REPORTEDBY,
TK.OWNER,
max(WF.ASSIGNCODE)
FROM ticket TK
INNER JOIN wfassignment WF on WF.OWNERID = TK.TICKETUID
WHERE TK.status not in ('效袝袪袧袨袙袠袣', '袟袗袣袪蝎孝', '袙蝎袩袨袥袧袝袧') AND WF.ASSIGNSTATUS not in ('COMPLETE', 'INACTIVE')
group by
TK.TICKETID,
TK.DESCRIPTION,
TK.CREATIONDATE,
TK.REPORTEDBY,
TK.OWNER
ORDER BY TK.TICKETID;
2021-05-16