Group by clause query

  • 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

  • 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

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply