sql server - How to unpivot set of table records and compare column values? -
i'm selecting top 2 records table ordered date descending. @ moment 2 records returned fine. need transform record data horizontal vertical compare column values. (i.e, column values new rows)
i came across solution of using unpivot
in case need join 2 records column name , compare both adding nett difference.
so data being returned no linkage betwen 2 records:
servercounts proservercount ------------ -------------- 20 6 25 7
but want present comparison between 2 record's column values :
previousweek currentweek nett ------------ ----------- ---- 25 20 5 7 6 1
question:
how can unpivot 2 table records , compare column values?
now stored procedure looks returning 2 top records:
alter procedure [dbo].[getservercount] begin select top 2 [servercounts],[proservercount] [db].[dbo].[servers] order [date] desc end
Comments
Post a Comment