1

我有一个查询返回估计的日期和时间戳。每个估计可以有多个时间戳。我只需要第一个和最后一个印章。我怎样才能做到这一点?我的查询如下所示:

SELECT LogDateTime, Operator, Program, Explanation, TransactionCode
FROM SystemLog
WHERE Program = 'Estimating'
ORDER BY TransactionCode
4

1 回答 1

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
于 2012-12-15T01:42:42.200 回答