本文介绍了MySQL的.选择年份范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我下面列出了数据库.如您所见,每种型号都有多年的范围.例如,在2008-2010
I've got database listed below. As you can see, there is a range of years for each model. For example, Infiniti EX35
in range of 2008-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
如何进行这样的紧凑选择?
How can I make compact selection like this?
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
这篇关于MySQL的.选择年份范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!