我的设施数据有如下记录。
Id_facility | time_start | time_end
1 | 07:00:00 | 19:00:00
2 | 08:00:00 | 20:00:00
我想在一个查询中获取lowest time_start
和highest time_end
,
例如:07:00:00,20:00
我的尝试:
SELECT time_start, MIN( TIME_TO_SEC(time_start)), time_end, MAX( TIME_TO_SEC(time_end)) AS mite FROM facility
但结果只返回第一行。
如何在一个查询中获得最低time_start和最高time_end?**
答案 0 :(得分:0)
你想要得到两个结果吗?一个开始时间最短,另一个开始时间最长?
SELECT time_start, time_end
FROM facility
WHERE time_start = MIN( TIME_TO_SEC(time_start))
OR time_end = MAX( TIME_TO_SEC(time_end))
FROM facility
答案 1 :(得分:0)
我猜这就是你想要的:
MySQL 5.5.32架构设置:
CREATE TABLE facility
(`Id_facility` int, `time_start` varchar(8), `time_end` varchar(8))
;
INSERT INTO facility
(`Id_facility`, `time_start`, `time_end`)
VALUES
(1, '07:00:00', '19:00:00'),
(2, '08:00:00', '20:00:00')
;
查询1 :
SELECT MIN( time_start), MAX( time_end) FROM facility
<强> Results 强>:
| MIN( TIME_START) | MAX( TIME_END) |
|------------------|----------------|
| 07:00:00 | 20:00:00 |