我有一张桌子:
CREATE TABLE IF NOT EXISTS `ccu_log` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`ccu` int(10) DEFAULT NULL,
`time` time DEFAULT NULL,
`date` date DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5626 ;
--
-- Dumping data for table `ccu_log`
--
INSERT INTO `ccu_log` (`id`, `ccu`, `time`, `date`) VALUES
(1, 0, '22:27:30', '2015-01-08'),
(2, 0, '22:29:01', '2015-01-08'),
(3, 0, '22:30:31', '2015-01-08'),
(4, 0, '22:32:01', '2015-01-08'),
(5, 3, '22:33:31', '2015-01-08'),
(6, 0, '22:35:01', '2015-01-08'),
(7, 4, '22:36:31', '2015-01-08'),
(8, 8, '22:38:01', '2015-01-09'),
(9, 5, '22:39:31', '2015-01-09'),
(10, 1, '22:41:01', '2015-01-09');
当我想要使用mysql查询选择数据时:
SELECT *
FROM `ccu_log`
WHERE UNIX_TIMESTAMP("date") = UNIX_TIMESTAMP('09-01-2015')
显示我表格中的所有行。如果我用户查询:
SELECT * FROM `ccu_log` where UNIX_TIMESTAMP(date) = UNIX_TIMESTAMP('09-01-2015')
它没有返回预期的结果。
有什么建议吗?
答案 0 :(得分:1)
当该字段已经是date
类型时,您甚至不需要转换为时间戳进行比较。只是做
SELECT * FROM `ccu_log` WHERE `date`='2015-01-09'
答案 1 :(得分:0)
请尝试这样,
SELECT * FROM `ccu_log` where DATE_FORMAT(date,"%d-%m-%Y") = '09-01-2015';