Can anyone help me rewrite this query without a distinct clause?
select
a.rec_type ,
count(distinct a.a_tel_id) as count_distinct,
a.time_key as hour
from v_f_view as a with (nolock)
group by rec_type,time_key
I foud with the execution plans that this query takes too long and I want to optimize it.
query plan : http://postimage.org/image/p1myi9tw/
Indexes
Your problem is not the
DISTINCTclause but the lack of indexes. TheDISTINCTclause could be replaced by twoGROUP BYclauses but this will most likely suffer the same performance penalty.SQL Statement