2010-06-10 138 views
0

我已经跟踪与ID,SESSION_ID表tbl_track,CREATED_DATE领域帮助优化SQL查询

我需要算独特的session_id一天

在这里我得到了什么:

select count(0) 
from (
     select distinct session_id 
     from tbl_track 
     where created_date between getdate()-1 and getdate() 
     group by session_id 
)tbl 

IM的感觉,它可能是更好的解决方案

回答

5
select count(distinct session_id) 
from tbl_track 
where created_date between getdate()-1 and getdate() 
+0

但在这里,我会得到许多行(计数每个SESSION_ID),但我需要的是一个行与所有独特的session_id – Sasha 2010-06-10 04:25:50

+0

计数误解了这个问题。编辑答案。 – 2010-06-10 04:27:03

5

为什么不只是做你想要的东西?

select count(distinct session_id) 
    from tbl_track 
    where created_date between getdate()-1 and getdate() 
+0

发誓我没有复制,虽然格式相似是不可思议的... – 2010-06-10 04:36:37