Hello,
Could somebody explain me why the ordering has been changed ? In these two examples. First Query returns order by empid, but why it changes in the second one ? Why everything in order by orderdate ?
Am I missing something ?
SELECT empid, YEAR(orderdate) AS orderyear FROM Sales.Orders WHERE custid = 71 GROUP BY empid, YEAR(orderdate); This query returns the following output. empid orderyear ----------- ----------- 1 2006 1 2007 1 2008 2 2006 2 2007 2 2008 3 2007 4 2007 4 2008 5 2007 6 2007 6 2008 7 2007 7 2008 8 2007 9 2006
Second Query.
SELECT empid, YEAR(orderdate) AS orderyear, SUM(freight) AS totalfreight, COUNT(*) AS numorders FROM Sales.Orders WHERE custid = 71 GROUP BY empid, YEAR(orderdate); This query generates the following output. empid orderyear totalfreight numorders ----------- ----------- --------------------- ----------- 1 2006 126.56 1 2 2006 89.16 1 9 2006 214.27 1 1 2007 711.13 2 2 2007 352.69 1 3 2007 297.65 2 4 2007 86.53 1 5 2007 277.14 3 6 2007 628.31 3 7 2007 388.98 1 8 2007 371.07 4 1 2008 357.44 3 2 2008 672.16 2 4 2008 651.83 3 6 2008 227.22 1 7 2008 1231.56 2