我有一个查询,返回估算的日期和时间戳。每个估计可以有多个时间戳。我只需要第一张和最后一张邮票。我怎么能做到这一点?我的查询如下:
SELECT LogDateTime, Operator, Program, Explanation, TransactionCode
FROM SystemLog
WHERE Program = 'Estimating'
ORDER BY TransactionCode
答案 0 :(得分:0)
使用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