我必须下表:
CREATE TABLE IF NOT EXISTS `ebets_odds` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`match_id` int(11) NOT NULL,
`opponent_id` int(11) NOT NULL,
`value` float NOT NULL,
PRIMARY KEY (`id`),
KEY `match_id` (`match_id`),
KEY `opponent_id` (`opponent_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
INSERT INTO `ebets_odds` (`id`, `datetime`, `match_id`, `opponent_id`, `value`) VALUES
(1, '2013-09-04 23:09:39', 1, 1, 1.2),
(2, '2013-09-04 23:09:39', 1, 2, 1.8),
(3, '2013-09-05 11:54:10', 1, 1, 1.1),
(4, '2013-09-05 11:54:10', 1, 2, 1.9);
我想得到以下 SQL 结果:
2013-09-04 23:09:39 | 1.2 | 1.8
2013-09-05 11:54:10 | 1.1 | 1.9
所以我想按日期时间按条目分组。我试过这个,但它不起作用。
SELECT ODDS_1.datetime, ODDS_1.value AS odds_1, ODDS_2.value AS odds_2
FROM ebets_odds ODDS_1, ebets_odds ODDS_2
WHERE ODDS_1.match_id = 1 AND ODDS_2.match_id = 1
GROUP BY ODDS_1.datetime