Select distinct returns duplicates
I have the following query:
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;
But it returns duplicates in TK.TICKETID attribute. And if i remove other attributes all ok. eg
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 my question is simple but I can't solve it by myself. Will be greatfull for any kind of help.
尝试这个:
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;
There are multiple columns in the select query, the query check for uniqueness across all the columns, not just the one in brackets.
The SQL DISTINCT keyword is used in conjunction with SELECT statement to eliminate all the duplicate records and fetching only unique records. . Please note it not just columns
If you modify your query to this:
SELECT
DISTINCT (TK.TICKETID),
TK.DESCRIPTION,
TK.CREATIONDATE,
TK.REPORTEDBY,
TK.OWNER
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;
You will get just one result.
In the output, please note the following, the starred ones are all different.
TK.TICKETID TK.DESCRIPTION TK.CREATIONDATE TK.REPORTEDBY TK.OWNER **WF.ASSIGNCOD**E
О1013249 Право доступа 02.06.14 CHERNOVDK SKACHKOVSV **NOVIKOVVA**
О1013249 Право доступа 02.06.14 CHERNOVDK SKACHKOVSV **PRITULADV**
О1013249 Право доступа 02.06.14 CHERNOVDK SKACHKOVSV **SVESHNIKOVAV**
链接地址: http://www.djcxy.com/p/82644.html
上一篇: 是否可以在Rust中打印一个用千位分隔符格式化的数字?
下一篇: 选择不同的退货重复