Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kwacz23
Starting Member
44 Posts |
Posted - 2011-10-23 : 13:20:19
|
| Hey,Please help me with grouping. how does it work in this example?what is the difference between grouping or without grouping in this example?SELECT orderid, GROUPING (orderid),productid, GROUPING (productid),SUM(quantity) AS total_quantityFROM [order details]WHERE orderid < 10250GROUP BY orderid, productidWITH CUBEORDER BY orderid, productid |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-23 : 13:44:48
|
| the rows for which grouping gets 1 indicates they're summary values for group based on orderid/productid values and for them there will be NULL value in fields orderid/productid. any other NULL valued record for them with grouping value as 0 means they're not part of aggregate but rather they denote the value for group of records with NULL values for orderid/productidYou will notice difference only if fields orderid/productid are Nullable.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|