我有一个查询返回估计的日期和时间戳。每个估计可以有多个时间戳。我只需要第一个和最后一个印章。我怎样才能做到这一点?我的查询如下所示:
SELECT LogDateTime, Operator, Program, Explanation, TransactionCode
FROM SystemLog
WHERE Program = 'Estimating'
ORDER BY TransactionCode
我有一个查询返回估计的日期和时间戳。每个估计可以有多个时间戳。我只需要第一个和最后一个印章。我怎样才能做到这一点?我的查询如下所示:
SELECT LogDateTime, Operator, Program, Explanation, TransactionCode
FROM SystemLog
WHERE Program = 'Estimating'
ORDER BY TransactionCode
使用min()
和max()
聚合函数:
SELECT
min(LogDateTime) as first_LogDateTime,
max(LogDateTime) as last_LogDateTime,
Operator, Program, Explanation, TransactionCode
FROM SystemLog
WHERE Program = 'Estimating'
GROUP BY Operator, Program, Explanation, TransactionCode
ORDER BY TransactionCode