我的表结构是这样的,我正在使用laravel和postgres数据库
id | serving_start_time | serving_end_time
1 | 2016-10-05 00:24:08.894 | 2016-10-05 00:24:19.003
2 | 2016-10-05 00:24:59.875 | 2016-10-05 00:25:13.728
3 | 2016-10-05 11:43:52.055 | 2016-10-05 11:45:41.561
我想计算' total_serving_time'(serving_start_time-serving_end_time)并且只获得最小和最大的total_serving_time'。这可能在一个查询中?请帮忙
答案 0 :(得分:1)
在一个如下的查询中?
SELECT
MIN(serving_end_time - serving_start_time) AS min_total_serving_time,
MAX(serving_end_time - serving_start_time) AS max_total_serving_time
FROM table;