, . SQL Server PIVOT - . ORACLE CONNECT BY.
, , :
SELECT
T.UID,
MIN((SELECT Limit FROM TheTable A WHERE A.UID = T.UID AND Type = 'A')) A,
MIN((SELECT Limit FROM TheTable B WHERE B.UID = T.UID AND Type = 'B')) B,
MIN((SELECT Limit FROM TheTable C WHERE C.UID = T.UID AND Type = 'C')) C
FROM TheTable T
GROUP BY T.UID
The MIN function is used to avoid complaints from the database server that you do not include columns A, B, and C in the GROUP BY clause.
Sloppy and slow, but it works.
Another approach, which can be faster on most database systems (be careful with Cartesians here if one type has multiple entries for the UID):
SELECT
Driver.UID,
A.Limit A,
B.Limit B,
C.Limit C
FROM TheTable Driver
INNER JOIN TheTable A ON Driver.UID = A.UID AND A.Type = 'A'
INNER JOIN TheTable B ON Driver.UID = B.UID AND B.Type = 'B'
INNER JOIN TheTable C ON Driver.UID = C.UID AND C.Type = 'C'
source
share