Home Forums SQL Server 2008 T-SQL (SS2K8) trying to add alias for value generated by Where clause RE: trying to add alias for value generated by Where clause

  • polkadot (7/31/2012)


    ---QUERY that returns cumulative total by DayCount

    SELECT a.DayCount,

    a.Sales,

    SUM(b.Sales)

    FROM Sales a

    CROSS JOIN Sales b

    WHERE (b.DayCount <= a.DayCount) --AS RunningTotal

    GROUP BY a.DayCount,a.Sales

    ORDER BY a.DayCount,a.Sales

    Be very careful there. What you've got is a triangular join, which is going to cost a lot in terms of performance. Have a look at this article --> http://www.sqlservercentral.com/articles/T-SQL/61539/%5B/url%5D for more information.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/