SELECT * FROM title
gives me the following output:
title_number version_type hd_sd
1000046 Standard SD
1000046 Standard HD
1000050 Standard SD
1000093 Standard SD
1000093 Standard HD
1000125 Standard SD
1000269 Standard SD
I need to get all distinct title_numbers and then hd_sd will = HD
if that exists, otherwise, it will = SD
. The correct output would be:
title_number version_type hd_sd
1000046 Standard HD
1000050 Standard SD
1000093 Standard HD
1000125 Standard SD
1000269 Standard SD
The closest I got to this was SELECT * FROM title GROUP BY title_number
, but that does not give me the correct hd_sd
column value. How would I correctly do this query?
SELECT title_NUMBer, Version_type,
MIN(hd_sd)
FROM tableName
GROUP BY title_NUMBer
for improvements,
SELECT a.*
FROM tableName a
INNER JOIN
(
SELECT title_NUMBer, MIN(hd_sd) minCol
FROM tableName
GROUP BY title_NUMBer
) b ON a.title_number = b.title_Number AND
a.hd_sd = b.mincol
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.