SELECT *
FROM
( SELECT [DataName] ,
[CollectionTime] ,
[DataValue]
FROM
HistoryData where DataFlag = '2061'
)
p PIVOT
( SUM([DataValue]) FOR [DataName] IN ( [PH值],[水温]) )
AS pvt
ORDER BY pvt.[CollectionTime];
select DataName,Code,CollectionTime ,Datavalue
from HistoryData where CollectionTime >='2015-01-01 00:00:00'and CollectionTime <'2016-01-01 00:00:00'
FROM
( SELECT [DataName] ,
[CollectionTime] ,
[DataValue]
FROM
HistoryData where DataFlag = '2061'
)
p PIVOT
( SUM([DataValue]) FOR [DataName] IN ( [PH值],[水温]) )
AS pvt
ORDER BY pvt.[CollectionTime];
select DataName,Code,CollectionTime ,Datavalue
from HistoryData where CollectionTime >='2015-01-01 00:00:00'and CollectionTime <'2016-01-01 00:00:00'
and DataFlag = '2061'