March 9, 2010 at 6:16 pm
Basically, page 3 blew me away 😀
March 10, 2010 at 5:54 am
Oleg, thank you very much for the time and explanation, you couldn't have been clearer. i'm gonna play with your code at lunch time :p .
I've learned a lot more than the count_big function out of this.
TYVM again!
Greetings!
March 10, 2010 at 11:08 pm
why SELECT COUNT_BIG(*) not return same result????????????
i hope:cool: 1,2,and 3 are correct
March 11, 2010 at 8:49 am
ravindraee24 (3/10/2010)
why SELECT COUNT_BIG(*) not return same result????????????i hope:cool: 1,2,and 3 are correct
There is an explanation by sknox on page 2 of this discussion, which clearly explains why 2 and 3 are the only correct options. Please read the post by sknox. There are more related posts after that, on page 3.
Oleg
March 12, 2010 at 6:39 pm
This was a very very good question.
Event I read the remark section in SQL Server 2008 Books Online about Count_big
(
COUNT_BIG(*) returns the number of items in a group. This includes NULL values and duplicates.
COUNT_BIG(ALL expression) evaluates expression for each row in a group and returns the number of nonnull values.
COUNT_BIG(DISTINCT expression) evaluates expression for each row in a group and returns the number of unique, nonnull values.
)
, I got it wrong and did not understand why my answer was wrong until I had read all the 4 pages of reply...
Thanks you all!
March 15, 2010 at 12:51 pm
I used deductive reasoning more than SQL skills to guess this right 😀
I assumed Number 1 would return both columns, the other 3 would return only column 2 and number 4 would include one NULL (doesn't DISTINCT include one NULL?) so I assumed that ALL was the default and would therefore make 2 and 3 have identical results. But I guessed 😀
Is my explanation close to being right?
Peter Trast
Microsoft Certified ...(insert many literal strings here)
Microsoft Design Architect with Alexander Open Systems
March 18, 2010 at 5:50 pm
r5d4 (3/9/2010)
the answer is I and II , not II and III.does anyone audit these questions? i want my point (joke) 🙂
That was my answer too but it's wrong. I forgot that ALL is the default value for first argument, not *. It can't be I and II, because (*) will count null values, none of the other options will.
Cheers!
March 21, 2010 at 8:02 am
Interesting question... adds to the sql vocabulary...
Jamie
March 30, 2010 at 8:14 am
Good question, thank you.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 15, 2010 at 12:13 am
The ans given here is wrong;
i used here
declare @temp table (num int, numdesc varchar(50))
insert @temp select 1, 'one'
union select 2, 'two'
union select 3, null
union select 4, 'four'
union select 5, null
i) select count_big(*) from @temp
ii) select count_big(num) from @temp
iii) select count_big(numdesc) from @temp
iv) select count_big(all numdesc) from @temp
v) select count_big(distinct numdesc) from @temp
and the same result were from
a) i) and ii)
b) iii), iv) and v)
May 20, 2010 at 12:52 am
Hi,
I. SELECT COUNT_BIG(*)
II. SELECT COUNT_BIG(column_2)
III. SELECT COUNT_BIG(ALL column_2)
IV. SELECT COUNT_BIG(DISTINCT column_2)
I Answered this question selecting II,III and IV (which actually is a correct answer) guess what i was indicated as INCORRECT! Pls let me know if I am so.
coz all the three (2,3,4) have same output.
May 20, 2010 at 3:09 am
Avaneesh -388582 (5/20/2010)
Hi,I. SELECT COUNT_BIG(*)
II. SELECT COUNT_BIG(column_2)
III. SELECT COUNT_BIG(ALL column_2)
IV. SELECT COUNT_BIG(DISTINCT column_2)
I Answered this question selecting II,III and IV (which actually is a correct answer) guess what i was indicated as INCORRECT! Pls let me know if I am so.
coz all the three (2,3,4) have same output.
Wow! That's amazing! What code did you use to come to that conclusion? I used this:
DECLARE @QotD
TABLE (
Column_1 TINYINT NOT NULL,
Column_2 TINYINT NULL
);
INSERT @QotD VALUES (1, 1);
INSERT @QotD VALUES (2, NULL);
INSERT @QotD VALUES (3, 2);
INSERT @QotD VALUES (4, 2);
INSERT @QotD VALUES (5, NULL);
INSERT @QotD VALUES (6, 3);
INSERT @QotD VALUES (7, 4);
INSERT @QotD VALUES (8, 5);
INSERT @QotD VALUES (9, 6);
INSERT @QotD VALUES (10, 7);
--I.
SELECT COUNT_BIG(*) FROM @QotD;
--II.
SELECT COUNT_BIG(Column_2) FROM @QotD;
--III.
SELECT COUNT_BIG(ALL Column_2) FROM @QotD;
--IV.
SELECT COUNT_BIG(DISTINCT Column_2) FROM @QotD;
I Answered this question selecting II,III (which actually is a correct answer) guess what i was indicated as CORRECT! Pls let me know if I am so. coz all the two (2,3) have same output. :laugh:
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
September 27, 2010 at 5:22 pm
All is by default so II & III are same expressions
April 29, 2011 at 7:52 am
I think this question could have been worded better and is incomplete.
August 30, 2012 at 1:24 am
explination given here is not fully correct-->"SELECT COUNT_BIG(ALL COlumn_2) and SELECT COUNT_BIG(column_2). COUNT_BIG(all column_2) will count all rows from the table (including duplicate & null rows). COUNT_BIG(DISTINCT column_2) will evaluate distinct non-null values.
:discuss:
because --->
"COUNT_BIG(all column_2) will count all rows from the table including duplicate & Excluding null rows).
and
COUNT_BIG(*) will count all rows from the table (including duplicate & null rows).
Viewing 15 posts - 31 through 45 (of 45 total)
You must be logged in to reply to this topic. Login to reply