我有下面列出的数据库。如您所见,每种型号都有不同的年份。例如,Infiniti EX352008-2010范围内

Infiniti    EX35    2010    3.5 V6
Infiniti    EX35    2009    3.5 V6
Infiniti    EX35    2008    3.5 V6
Infiniti    EX37    2007    3.7i V6
Infiniti    EX37    2008    3.7i V6
Infiniti    EX37    2009    3.7i V6
Infiniti    EX37    2010    3.7i V6
Infiniti    FX35    2003    3.5 V6
Infiniti    FX35    2004    3.5 V6
Infiniti    FX35    2005    3.5 V6
Infiniti    FX35    2006    3.5 V6
Infiniti    FX35    2007    3.5 V6
Infiniti    FX35    2008    3.5 V6

我怎样才能做出这样紧凑的选择呢?
Infiniti    EX35    2008-2010   3.5 V6
Infiniti    EX37    2007-2010   3.7i V6
Infiniti    FX35    2003-2008   3.5 V6

谢谢您!

最佳答案

SELECT Make, Model,
    CASE
      WHEN MIN(Year) = MAX(Year)
        THEN MIN(Year)
      ELSE CONCAT(MIN(Year), '-', MAX(Year))
    END As Year,
    OtherColumns
FROM tableName
GROUP BY Make, Model, OtherColumns

10-01 14:11