简体   繁体   English

帮助优化sql查询

[英]help optimize sql query

I have tracking table tbl_track with id, session_id, created_date fields 我有包含id,session_id,created_date字段的跟踪表tbl_track

I need count unique session_id for one day 我需要计算一天的唯一session_id

here what i got: 这是我得到的:

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 feeling that it could be better solution for it 我觉得这可能是更好的解决方案

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

Why not just do exactly what you ask for? 为什么不完全按照您的要求做呢?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM