我有一个如下所示的查询:
SELECT time_stop, some_count
FROM foo
WHERE user_id = 1
AND time_start >= '2016-07-27 00:00:00'
AND time_stop <= '2016-07-27 23:59:59'
AND some_count = ( SELECT MAX(some_count)
FROM foo
WHERE user_id = 1
AND tm_start >= '2016-07-27 00:00:00'
AND tm_stop <= '2016-07-27 23:59:59'
);
Run Code Online (Sandbox Code Playgroud)
表架构如下所示:
Create Table: CREATE TABLE `foo` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`time_start` datetime(6) DEFAULT NULL,
`time_stop` datetime(6) DEFAULT NULL,
`some_count` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),,
KEY `user_id` (`user_id`),
KEY …Run Code Online (Sandbox Code Playgroud)