sql server - Count distinct by multiple columns takes a long time -


i'm trying perform count distinct in sql server, 2 fields.

i've tried 2 different ways. the first 1 concatenation:

select count (distinct concat ([ucid],[callsegment]))  ivr_lines ucid in (select ucid [epmtest].[dbo].[ivr_lines] module = 'hozlap' , event_name = 'a3' , event_value in ('1','2','3') , date> 20160911) , event_name = 'a6' or  event_name = 'a7' 

while the second 1 using sub-query:

select count(*) from( select distinct ucid,callsegment  ivr_lines ucid in (select ucid [epmtest].[dbo].[ivr_lines] module = 'hozlap' , event_name = 'a3' , event_value in ('1','2','3') , date> 20160911) , event_name = 'a6' or  event_name = 'a7' )a 

they take same running time (more 10 seconds, due inner query itself). however, know - 1 more efficient? method should choose?

thanks

i think wrong queries

first date > 20160911 should give error, try replace date > '20160911'

second and event_name = 'a6' or event_name = 'a7'
very different and (event_name = 'a6' or event_name = 'a7')

with syntax queries count many more records (i think) expected , problem of slow execution time

talking best... same optimizer

you should add info primary key, indexes, number of records , example of data.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -