时间戳..只需要第一个和最后一个

时间:2012-12-15 01:31:34

标签: mysql

我有一个查询,返回估算的日期和时间戳。每个估计可以有多个时间戳。我只需要第一张和最后一张邮票。我怎么能做到这一点?我的查询如下:

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

1 个答案:

答案 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