我有一种情况,我需要查询每个6值= 0背靠背为1。
SELECT count(price) FROM TABLE WHERE p_value = 0 AND availability ="outofstock"
我需要它将每6个背对背结果计为一个,如果有的话 12结果计数应该返回2并且如果有其他奇数或偶数数字如13背靠背或16背靠背它应该忽略如果有18个结果它应该返回3。
CREATE TABLE IF NOT EXISTS `test` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`price` int(5) NOT NULL,
`p_value` int(5) NOT NULL,
`availability` varchar(20) NOT NULL,
`product_id` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=26 ;
INSERT INTO `test` (`id`, `price`, `p_value`, `availability`, `product_id`) VALUES
(1, 10, 0, 'outofstock', 3),
(2, 10, 0, 'outofstock', 3),
(3, 10, 0, 'outofstock', 3),
(4, 10, 0, 'outofstock', 3),
(5, 10, 0, 'outofstock', 3),
(6, 10, 0, 'outofstock', 3),
(7, 10, 0, 'outofstock', 3),
(8, 10, 0, 'outofstock', 3),
(9, 10, 0, 'outofstock', 3),
(10, 10, 0, 'outofstock', 3),
(11, 10, 0, 'outofstock', 3),
(12, 10, 0, 'outofstock', 3),
(13, 10, 0, 'outofstock', 3),
(14, 10, 3, 'available', 5),
(15, 10, 1, 'available', 2),
(16, 10, 0, 'outofstock', 99),
(17, 10, 3, 'available', 8),
(18, 10, 4, 'available', 30),
(19, 10, 0, 'outofstock', 26),
(20, 10, 0, 'outofstock', 12),
(21, 10, 0, 'outofstock', 3),
(22, 10, 0, 'outofstock', 3),
(23, 10, 0, 'outofstock', 3),
(24, 10, 0, 'outofstock', 11),
(25, 10, 0, 'outofstock', 3);