SQL Server command with Pivot

  • 52
  • 0

SQL Server command with Pivot

Select * 
From ( Select CompetitorInfo.CompetitorName,
              CompetitorInfo.Years,
              CompetitorInfo.Budget
       From CompetitorInfo
       where  AnalyzeTime in (select top 1 AnalyzeTime from CompetitorInfo order by recno desc) 
       and CompetitorInfo.CompanyName = 'xx公司'
       ) as TmpTable
PIVOT (
    Avg(Budget)
    For Years in ([2019],[2018],[2017],[2016],[2015])
        
    ) as PivotTable