SQL Server - Convert Days as Column, Hour as row -
i'm looking way convert rows display datetime data's day column , hour first row in 1 month. example data in month:
time | value -------------------------------- 2016-10-01 00:00:00 | 23 2016-10-01 00:30:00 | 35 ..... | ..... 2016-10-31 23:30:00 | 52
the result want is
time | 1 | .... | 31 | <-- day 1 - 31 --------------------------------------- 00:00:00 | 23 | .... | .... | 00:30:00 | 35 | .... | .... | ... | .... | .... | .... | 23:30:00 | .... | .... | 52 |
how can build result?
you can use conditional aggregate
this
select cast([time] time), max(case when day([time]) = 1 value end) [1] max(case when day([time]) = 2 value end) [2] max(case when day([time]) = 3 value end) [3] ..... max(case when day([time]) = 31 value end) [31] yourtable month([time]) = 10 -- pass required month group cast([time] time)
Comments
Post a Comment