Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Group by clause query Expand / Collapse
Author
Message
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: Thursday, September 25, 2014 2:43 AM
Points: 35, Visits: 54
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?


Thanks

Subhro


  Post Attachments 
query1.JPG (39 views, 147.07 KB)
query2.JPG (27 views, 166.47 KB)
table-Sales.Orders.JPG (13 views, 309.32 KB)
Post #923318
Posted Tuesday, May 18, 2010 5:48 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, December 8, 2014 10:03 AM
Points: 111, Visits: 499
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.

Nag


Nag
------------------------------------------------
How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537
Post #923476
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse