SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Group by clause query


Group by clause query

Author
Message
Shintu
Shintu
SSC Veteran
SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)

Group: General Forum Members
Points: 253 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?


Thanks

Subhro
Attachments
query1.JPG (63 views, 147.00 KB)
query2.JPG (44 views, 166.00 KB)
table-Sales.Orders.JPG (27 views, 309.00 KB)
Nagesh S-432384
Nagesh S-432384
Right there with Babe
Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)

Group: General Forum Members
Points: 792 Visits: 579
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search