如何优化具有日期内部选择查询的查询?

时间:2011-11-21 17:17:31

标签: sql sql-server oracle tsql

查询是:

select sum(value) 
  from TAB 
 where TimeStamp=
     {
         select max(TimeStamp)
           from TAB where col1=12 and col2=18
     }
   and col1=12 and col2=18;

我试图通过消除子查询来改进它。如果可能的话。

1 个答案:

答案 0 :(得分:1)

试试这个:

select sum(value) 
  from TAB 
 where col1=12 and col2=18
 group by TimeStamp
 order by TimeStamp desc
 limit 1