【发布时间】:2010-11-30 23:22:17
【问题描述】:
嗨,我正在尝试进行查询,该查询将从表中运行记录,并且在两年之间它工作正常,但我需要列出我在 BETWEEN 之间搜索的所有值
查询
select SUM(price) FROM orders where year BETWEEN 2004 and 2009 GROUP BY year
2005 | 200
2006 | 100
2008 | 400
i am trying to show like this
2005 | 200
2006 | 100
2007 | 0
2008 | 400
2009 | 0
-- ----------------------------
-- Table structure for `orders`
-- ----------------------------
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`price` decimal(10,0) DEFAULT NULL,
`year` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records of orders
-- ----------------------------
INSERT INTO orders VALUES ('1', '200', '2005');
INSERT INTO orders VALUES ('2', '100', '2006');
INSERT INTO orders VALUES ('3', '400', '2008');
或者我是否需要在 php 中通过一些循环或任何建议来执行此操作 感谢帮助
【问题讨论】: