gpt4 book ai didi

php - MySQL。选择年份范围

转载 作者:行者123 更新时间:2023-11-29 04:29:26 24 4
gpt4 key购买 nike

我有下面列出的数据库。如您所见,每个模型都有一个年份范围。例如,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

关于php - MySQL。选择年份范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5437052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com