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


Accessing and changing data 2008


Accessing and changing data 2008

Author
Message
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5693 Visits: 25280
Comments posted to this topic are about the item Accessing and changing data 2008

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
Iggy-SQL
Iggy-SQL
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2963 Visits: 440
Either I read the BOL totally wrong, or you got the answer totally wrong.

The BOL (linked in your answer) says they are equivalent. Unless "equivalent" does not equal to "the same"?

Specifying GROUPING SETS ( [,...n ]) as the GROUP BY list is equivalent to a UNION ALL of queries, each with one of the grouping sets as its GROUP BY list. Aggregates on floating-point numbers might return slightly different results.

The following statements are equivalent:

SELECT customer, year, SUM(sales)
FROM T
GROUP BY GROUPING SETS ((customer), (year))


SELECT customer, NULL as year, SUM(sales)
FROM T
GROUP BY customer
UNION ALL
SELECT NULL as customer, year, SUM(sales)
FROM T
GROUP BY year



Urbis, an urban transformation company
sabinweb
sabinweb
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2737 Visits: 668
And how do I know that "sales" is a floating-point numbers ?
i guess ?
ChiragNS
ChiragNS
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2409 Visits: 1865
Hey i thought the answer is "They are the same".

"Keep Trying"
HanShi
HanShi
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3049 Visits: 3633
According to the link provided in the answer, the query with the GROUPING SETS equals the query with the GROUP BY and UNION ALL.
The correct answer of QotD should be "both queries are the same".

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
liam.stirling
liam.stirling
SSC-Addicted
SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)

Group: General Forum Members
Points: 469 Visits: 124
I thought "The following statements are equivalent" meant they were the same.

Silly me!
Tao Klerks
Tao Klerks
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1393 Visits: 1249
Sorry to whine, but this question is a little disappointing - It's educational on at least two counts (grouping sets - new feature, and possible gotcha on floating point numbers), but ultimately what does it mean for two queries to be "the same"?

Do you judge based on the results? The query plan? The syntax?

Most people most of the time would be referring to "logical" equivalence - is the returned data set exactly the same regardless of the data set? And the answer to that question is, sadly, "It cannot be determined based on the information provided", as we would need to know the data structure of the table.

In case anyone reads this far, I do have a question: Do we know under what exact circumstances floating-point numbers (presumably Real and Float) will return different results? Can we assume Decimal types are exempt from this uncertainty?

http://poorsql.com for T-SQL formatting: free as in speech, free as in beer, free to run in SSMS or on your version control server - free however you want it.
daft
daft
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 153
liam.stirling (9/23/2008)
I thought "The following statements are equivalent" meant they were the same.

Silly me!


Exactly. Even though the resultsets might be slightly different, the statements are equivalent. Boooo, I want my point back! Smile

Also does this highlight an issue with floating point anomaly in grouping sets, or has this always been an issue with aggregate statements on floating points, ie a SQL Server bug?
liam.stirling
liam.stirling
SSC-Addicted
SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)

Group: General Forum Members
Points: 469 Visits: 124
Tao Klerks (9/23/2008)
Sorry to whine, but this question is a little disappointing - It's educational on at least two counts (grouping sets - new feature, and possible gotcha on floating point numbers), but ultimately what does it mean for two queries to be "the same"?

Do you judge based on the results? The query plan? The syntax?

Most people most of the time would be referring to "logical" equivalence - is the returned data set exactly the same regardless of the data set? And the answer to that question is, sadly, "It cannot be determined based on the information provided", as we would need to know the data structure of the table.

In case anyone reads this far, I do have a question: Do we know under what exact circumstances floating-point numbers (presumably Real and Float) will return different results? Can we assume Decimal types are exempt from this uncertainty?



I agree, Tao. There was an educational element to the question because I looked at something new, but there is also a semantic problem with the question, and even with reference to the BOL, I prefer your option of a third answer.
Richard M Karpel
Richard M Karpel
SSC Eights!
SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)SSC Eights! (973 reputation)

Group: General Forum Members
Points: 973 Visits: 62
I went to the link posted as an explanation [color=#00ffff]http://msdn.microsoft.com/en-us/library/bb510427.aspx[/color]
and the example listed at the top of the page is exactly the same as the question, and it says they are equivalent.

From the link above:

[color=#ff0000]The following statements are equivalent:
Copy Code

SELECT customer, year, SUM(sales)
FROM T
GROUP BY GROUPING SETS ((customer), (year))


Copy Code

SELECT customer, NULL as year, SUM(sales)
FROM T
GROUP BY customer
UNION ALL
SELECT NULL as customer, year, SUM(sales)
FROM T
GROUP BY year[/color]
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