我有一个以月份和年份为列的列。我需要从列中选择一个范围。它们似乎不适用于 2 个范围。
桌子
CREATE TABLE `sampletable` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`AccountId` int(11) unsigned NOT NULL,
`CampaignId` int(11) unsigned NOT NULL,
`CampaignName` varchar(115) NOT NULL DEFAULT '',
`Sent` int(11) unsigned NOT NULL,
`Month` int(11) unsigned NOT NULL,
`Year` int(11) unsigned NOT NULL,
`LocationId` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `AccountId_idx` (`AccountId`),
KEY `monthy_year_idx` (`Month`,`Year`),
KEY `locationid_idx` (`LocationId`)
) ENGINE=MyISAM AUTO_INCREMENT=1584
选择语句:
SELECT * FROM sampletable
WHERE AccountId = 1
and (`Month` >= 10 AND `Year` = 2012)
and (`Month` <= 2 AND `Year` = 2013)
ORDER BY Year asc, month asc
这似乎不起作用。
我是否必须将这些转换为日期格式并在两者之间使用?