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.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 which column to count?

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 avgsalesamountperorderline
From Sales.orders as o
Inner join sales.orderdetails as d on o.orderid = d.orderid
GROUP BY o.orderid, o.orderdate
Order 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.
Go to Top of Page

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.

Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -