Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Sum and Count


Sum and Count

Author
Message
chgn01
chgn01
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1732 Visits: 1800
Comments posted to this topic are about the item Sum and Count

--------------------------------------
;-)“Everything has beauty, but not everyone sees it.” ― Confucius
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6221 Visits: 25280
Nice question - learned something from it ... Again thanks

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
kapil_kk
kapil_kk
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2583 Visits: 2764
Nice question... learn something new today.. :-)
But can anyone plz explain me about the SUM part which is returning 12, I am not clear with this section w00t

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Danny Ocean
Danny Ocean
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1452 Visits: 1549
kapil_kk (4/17/2013)
Nice question... learn something new today.. :-)
But can anyone plz explain me about the SUM part which is returning 12, I am not clear with this section w00t


Kapil, Cross join means Cartesian product. When query have multiple joins, it solve it from left to right. So first cross join take place between table #T1 and #T2. It gives 2 (1 *2) rows. Now these 2 rows have cross join with #T3. It gives 6 (2*3) rows. Output of this query look like below.


id1 id2 id3
1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3

Now calculate sum of column id3. its 1+2+3+1+2+3 = 12.
So Total row count is 6 and total of id3 column is 12.

I think this help you. :-)

Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com
Kingston Dhasian
Kingston Dhasian
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3128 Visits: 5078
kapil_kk (4/17/2013)
Nice question... learn something new today.. :-)
But can anyone plz explain me about the SUM part which is returning 12, I am not clear with this section w00t


Change the SELECT query like below and check the values of id3, you will understand why the result.
SELECT *
FROM #T1, #T2,#T3;




Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
kapil_kk
kapil_kk
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2583 Visits: 2764
Danny Ocean (4/17/2013)
kapil_kk (4/17/2013)
Nice question... learn something new today.. :-)
But can anyone plz explain me about the SUM part which is returning 12, I am not clear with this section w00t


Kapil, Cross join means Cartesian product. When query have multiple joins, it solve it from left to right. So first cross join take place between table #T1 and #T2. It gives 2 (1 *2) rows. Now these 2 rows have cross join with #T3. It gives 6 (2*3) rows. Output of this query look like below.


id1 id2 id3
1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3

Now calculate sum of column id3. its 1+2+3+1+2+3 = 12.
So Total row count is 6 and total of id3 column is 12.

I think this help you. :-)




Thanks Vinay...:-)
Its clear to me now :-)

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
demonfox
demonfox
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1327 Visits: 1192
bitbucket-25253 (4/17/2013)
Nice question ... Again thanks


+1

~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
John Mitchell-245523
John Mitchell-245523
SSCrazy Eights
SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)

Group: General Forum Members
Points: 9066 Visits: 15523
Are the exclamation marks in the explanation an expression of surprise, or are they supposed to represent factorials?

John
honza.mf
honza.mf
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1799 Visits: 1323
Danny Ocean (4/17/2013)

Kapil, Cross join means Cartesian product. When query have multiple joins, it solve it from left to right. So first cross join take place between table #T1 and #T2. It gives 2 (1 *2) rows. Now these 2 rows have cross join with #T3. It gives 6 (2*3) rows. Output of this query look like below.


id1 id2 id3
1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3

Now calculate sum of column id3. its 1+2+3+1+2+3 = 12.
So Total row count is 6 and total of id3 column is 12.

I think this help you. :-)



Just for counting the rows or sums in cartesian cross join it does not matter if you solve multiple joins from left or from right.



See, understand, learn, try, use efficient
© Dr.Plch
WWDMark
WWDMark
Say Hey Kid
Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)

Group: General Forum Members
Points: 663 Visits: 530
Danny Ocean (4/17/2013)
kapil_kk (4/17/2013)
Nice question... learn something new today.. :-)
But can anyone plz explain me about the SUM part which is returning 12, I am not clear with this section w00t


Kapil, Cross join means Cartesian product. When query have multiple joins, it solve it from left to right. So first cross join take place between table #T1 and #T2. It gives 2 (1 *2) rows. Now these 2 rows have cross join with #T3. It gives 6 (2*3) rows. Output of this query look like below.


id1 id2 id3
1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3

Now calculate sum of column id3. its 1+2+3+1+2+3 = 12.
So Total row count is 6 and total of id3 column is 12.

I think this help you. :-)


Thanks for the more in depth explanation, I was struggling to understand how we got 12 also!! Always learning! :-D


MCITP
MCTS - E-Business Card
Twitter: WWDMark

Try not! Do or do not, there is no try

email: info@weekendwebdesign.co.uk
Personal Website: www.markallen-online.co.uk
Business Website: www.weekendwebdesign.co.uk
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search