Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Group by clause query Expand / Collapse
Posted Tuesday, May 18, 2010 12:42 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, December 1, 2015 4:09 AM
Points: 35, Visits: 64
Hi ! All
I have a database TSQLFundamental2008, there I am trying to create a simple select query from Sales.Orders table. I am attaching two images for two different queries (Please go through the images),
where in one I have used a group by clause with empid, YEAR(orderdate) ;These two attributes. In another case i.e. in 2nd query I have made small change, rather than two I used 3 fields( added freight as a field under group by clause).Now if you go through the two O/P as showed in two images(query1.jpeg, query2.jpeg) that I have attached you will finds difference in those, I am also attaching the table structure of the Sales.Orders(table-Sales.Orders.jpeg). Can any body please tell me why two O/P are comming differently?



  Post Attachments 
query1.JPG (43 views, 147.07 KB)
query2.JPG (31 views, 166.47 KB)
table-Sales.Orders.JPG (14 views, 309.32 KB)
Post #923318
Posted Tuesday, May 18, 2010 5:48 AM


Group: General Forum Members
Last Login: Thursday, December 1, 2016 8:06 AM
Points: 111, Visits: 569
I think your results from both quires are very clear and your answer is right there, if you look at the out put 1st query (without grouping fright) grouped by empid 1 and year 2007 you are getting fright as 711.13 which is sum of 167.05 and 544.08 when you do the group by fright also result is split because fright on two rows are different. Hope you understood.


How to get the best help on a forum
Post #923476
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse