0

我正在尝试根据服务器名称从 oracle 表中获取最新值。我有以下sql:

SELECT T."Node",T."Timestamp",T."MAX_User_CPU_Pct", T."MAX_System_CPU_Pct" 
FROM DW.KPX_CPU_DETAIL_HV T where T."Node"='serverA%' and T."Timestamp"=
(select max(P."Timestamp") from DW.KPX_CPU_DETAIL_HV P where P."Node"='serverA%')

它似乎不起作用,有什么想法我可能在这里做错了吗?

4

2 回答 2

0
SELECT T."Node",T."Timestamp",T."MAX_User_CPU_Pct", T."MAX_System_CPU_Pct" 
FROM (SELECT * FROM DW.KPX_CPU_DETAIL_HV T where T."Node" like 'serverA%' ORDER BY T."Timestamp" DESC) T
 WHERE ROWNUM = 1

这为我做了,不确定这是最好的解决方案,但现在工作。

于 2013-06-11T14:57:01.557 回答
0

试试这个,实际上可能比子选择更快(即使它是正确的):

SELECT T."Node",
       T."Timestamp",
       T."MAX_User_CPU_Pct", 
       T."MAX_System_CPU_Pct" 
FROM (
  SELECT p.*, 
         row_Number() over (partition by p."Node" order by p."Timestamp" desc) as rn
  FROM DW.KPX_CPU_DETAIL_HV p
) t
where rn = 1;
于 2013-06-11T14:30:36.267 回答