Breaking News
Loading...
09/10/2013

1 câu hỏi về Select count(distinct...) trong SQL Server

create table #temp_test
(id int)

insert into #temp_test
 values(1)
insert into #temp_test
 values(NULL)
insert into #temp_test
 values(2)
insert into #temp_test
 values(3)
insert into #temp_test
 values(2)

select count(distinct id) 
 from #temp_test
What will be the result ? Choose your answer: 4 5 3 Correct answer: 3 Explanation: Distinct count() never considers NULL as a distinct value since NULL can be the same of other value. According to the documentation, COUNT returns unique, non-null values. Ref: COUNT - http://msdn.microsoft.com/en-us/library/ms175997.aspx

0 comments:

Post a Comment

 
Toggle Footer