|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 9:21 AM
Points: 5,099,
Visits: 20,191
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:02 PM
Points: 2,855,
Visits: 404
|
|
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
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:13 PM
Points: 1,762,
Visits: 403
|
|
And how do I know that "sales" is a floating-point numbers ? i guess ?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 5:02 AM
Points: 2,365,
Visits: 1,825
|
|
Hey i thought the answer is "They are the same".
"Keep Trying"
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 7:30 AM
Points: 1,114,
Visits: 1,140
|
|
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’! **
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Tuesday, January 08, 2013 7:08 AM
Points: 469,
Visits: 124
|
|
I thought "The following statements are equivalent" meant they were the same.
Silly me!
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Sunday, April 14, 2013 8:55 AM
Points: 1,383,
Visits: 1,212
|
|
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.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 7:29 AM
Points: 58,
Visits: 151
|
|
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! :)
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?
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Tuesday, January 08, 2013 7:08 AM
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.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, June 30, 2011 3:44 AM
Points: 971,
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]
|
|
|
|