Derived/calculated column on existing table

后端 未结 3 2010
盖世英雄少女心
盖世英雄少女心 2021-01-25 16:38

I have been going nuts over this issue for some time and I am seeking help.

I have SQL Server table with values, as follows:

Account - Date - Amount - Su         


        
3条回答
  •  不思量自难忘°
    2021-01-25 17:12

    SELECT    l.*, 
              q.summary AS SummaryPreviousYear
    FROM      lists l
    LEFT JOIN 
         (
              SELECT    Date, 
                        Summary
              FROM      lists 
              WHERE     MONTH(Date) = 12
         ) AS q  
              ON YEAR(l.Date) = YEAR(q.Date) + 1
    

提交回复
热议问题