Maison > Questions et réponses > le corps du texte
比如
2012-12-11 8:00:00-12:00:00
到
2012-12-13 8:00:00-12:00:00
这3天内,8点到12点。
查询语句怎么写?
自己写出来了。
EXPLAIN SELECT COUNT(*) FROM fd_member WHERE FROM_UNIXTIME(UNIX_TIMESTAMP(add_time),'%h')>=8 AND FROM_UNIXTIME(UNIX_TIMESTAMP(add_time),'%h')<12 GROUP BY CONVERT(add_time,CHAR(10))
不过,性能是个问题,谁有更好的办法。
表结构:
`mem_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `mem_name` varchar(50) NOT NULL , `mem_pass` varchar(50) NOT NULL , `telephone` varchar(20) DEFAULT NULL, `add_time` timestamp NULL DEFAULT NULL, PRIMARY KEY (`mem_id`), UNIQUE KEY `mem_card_id` (`mem_card_id`), UNIQUE KEY `mem_name` (`mem_name`)
阿神2017-04-17 11:06:06
SELECT * FROM table_name WHERE time BETWEEN unix_timestamp(2012-12-11 8:00:00) AND unix_timestamp(2012-12-11 12:00:00) OR time BETWEEN unix_timestamp(2012-12-12 8:00:00) AND unix_timestamp(2012-12-12 12:00:00) OR time BETWEEN unix_timestamp(2012-12-13 8:00:00) AND unix_timestamp(2012-12-13 12:00:00)