0

I have following sql query

SELECT  [POINT],[Timestamp],AvgValue=AVG(ValueNumeric)
FROM [myDatabase].[dbo].[Value] 
WHERE [Point] In (98,99,100,101,102,103,104,105) 
  AND Timestamp between DATEADD(DAY, -90, GETDATE()) and GETDATE() 
Group by [timestamp],[Point] 
order by [Timestamp], [Point]

which returns table as below

but I need to transpose this as below

Timestamp|Point1|Value1|Point2|Value2|Point3|Value3|

Is this doable?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Learner
  • 17
  • 6
  • 6
    What is your rbms? you need google for PIVOT or DYNAMIC PIVOT on your rdbms – Juan Carlos Oropeza Dec 22 '17 at 14:31
  • 4
    If the number/values of the points are not fixed or known, then you'd need some dynamic SQL here. You can find information on SO for this. – Tim Biegeleisen Dec 22 '17 at 14:32
  • 2
    The pivot query is an often asked question among the sql tag on SO. Please make an effort and report back with issues. – Parfait Dec 22 '17 at 14:43
  • 1
    Possible duplicate of [Convert Rows to columns using 'Pivot' in SQL Server](https://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server) – nathan_jr Dec 22 '17 at 23:52

0 Answers0