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 |
MelissaTsalicoglou
Starting Member
16 Posts |
Posted - 2014-06-05 : 07:04:14
|
How does this code figure out which column to count?Select o.orderid, o.orderdate, SUM(d.qty * d.unitprice) as totalsalesamount, count(*) as nooforderlines,AVG (d.qty * d.unitprice) as avgsalesamountperorderlineFrom Sales.orders as oInner join sales.orderdetails as d on o.orderid = d.orderidGROUP BY o.orderid, o.orderdateOrder by totalsalesamount DESC; |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2014-06-05 : 07:08:51
|
count(*) is counting rows which are grouped together by the same orderid and orderdate Too old to Rock'n'Roll too young to die. |
|
|
MelissaTsalicoglou
Starting Member
16 Posts |
Posted - 2014-06-05 : 07:14:08
|
Thanks :) so therefore it will group the order id column?quote: Originally posted by webfred count(*) is counting rows which are grouped together by the same orderid and orderdate Too old to Rock'n'Roll too young to die.
|
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2014-06-05 : 07:18:59
|
as you can see in GROUP BY it is grouping by orderid and inside that by orderdate Too old to Rock'n'Roll too young to die. |
|
|
|
|
|