0

SELECT * FROM title给我以下输出:

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

我需要获取所有不同的 title_numbers,然后 hd_sd 将 =HD如果存在,否则它将 = SD。正确的输出是:

title_number    version_type    hd_sd
1000046         Standard    HD
1000050         Standard    SD
1000093         Standard    HD
1000125         Standard    SD
1000269         Standard    SD

我最接近这个的是SELECT * FROM title GROUP BY title_number,但这并没有给我正确的hd_sd列值。我将如何正确执行此查询?

4

1 回答 1

2
SELECT title_NUMBer, Version_type,
        MIN(hd_sd)
FROM tableName
GROUP BY title_NUMBer

为了改进,

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
于 2012-10-11T23:36:57.490 回答