如何选择两个日期之间的所有日期?如何在mysql中选择两年之间的每一年?
我的表是这样的:
CREATE TABLE IF NOT EXISTS `product_modification` (
`id_product_modification` int(11) NOT NULL AUTO_INCREMENT,
`id_category` int(11) NOT NULL,
`id_sub_category` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`start_production_year` int(8) DEFAULT NULL,
`end_production_year` int(8) DEFAULT NULL,
`id_product_type` int(8) NOT NULL,
PRIMARY KEY (`id_product_modification`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `product_modification` (`id_product_modification`, `id_category`, `id_sub_category`, `name`, `start_production_year`, `end_production_year`, `id_product_type`) VALUES
(1, 1, 1, 'product_1', 2003, 2006, 1),
(2, 1, 1, 'product_2', 2009, 2011, 1),
(3, 1, 1, 'product_3', 2014, 2016, 1);
我想显示一排这样的:
id_product_modification | YEAR
------------------------------------------
1 | 2003
1 | 2004
1 | 2005
1 | 2006
2 | 2009
2 | 2010
2 | 2011
3 | 2014
3 | 2015
3 | 2016
有一个内置在这个功能呢?有没有办法让函数返回多行?
它必须是一个函数,因为我需要在其他SQL语句中使用它。
你能写代码吗我是新手 – Mil