日期:2014-05-16 浏览次数:20453 次
select a.tagname,b.transtype,a.times from
(select tagname,max(timestmp) as times from alarmlog group by tagname) a,
(select tagname,transtype,timestmp from alarmlog) b
where a.tagname = b.tagname and a.times = b.timestmp
你的代码应该等价于这个吧。。
SELECT
tagname,transtype,MAX(timestmp) AS times
FROM
alarmlog
GROUP BY
tagname,transtype
SELECT
tagname,transtype,MAX(timestmp) over(partition by tagname,transtype) AS times
FROM
alarmlog
和这个的结果呢?
SELECT
tagname,transtype,MAX(timestmp) over(partition by tagname) AS times
FROM
alarmlog
where
transtype='InAlm'