Answer the question
In order to leave comments, you need to log in
How to exclude duplicate values from the PIVOT operator?
Hello! there is a table (like an e-journal), I wanted to display data through a cross-request, but the fields are repeated
SELECT ID_KEY2,[2017-10-27],[2017-10-28]
FROM
(SELECT ID, ID_KEY2, OCENKA, DAT
FROM Journal2) p
PIVOT
(AVG(OCENKA) FOR DAT IN ( [2017-10-27],[2017-10-28] ) ) AS pvt ORDER BY pvt.ID_KEY2;
Answer the question
In order to leave comments, you need to log in
Well, remove the extra id before doing Pivot
(SELECT ID, ID_KEY2, OCENKA, DAT
FROM Journal2) p - here you have a subquery from which data is taken. Since simply writing DISTINCT will not work, it must be redone so that you have one date for each id.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question