我有一个查询,它会按类别给出一些属性作为结果,但我需要将每个类别转换为列
这是我的查询:
SELECT hist_statusevents.eqmt,
hist_exproot.shiftdate,
hist_statusevents.category,
Sum(hist_statusevents.duration/3600) as Value
FROM Powerview.dbo.hist_eqmtlist hist_eqmtlist,
Powerview.dbo.hist_exproot hist_exproot,
Powerview.dbo.hist_statusevents hist_statusevents
WHERE hist_exproot.shiftindex = hist_statusevents.shiftindex And
hist_statusevents.shiftindex = hist_eqmtlist.shiftindex And
hist_statusevents.eqmt = hist_eqmtlist.eqmtid And
hist_statusevents.eqmt like 'MOTO%'
GROUP BY hist_statusevents.eqmt,
hist_exproot.shiftdate,
hist_statusevents.category
这是查询的输出结果:
eqmt shiftdate category Value
MOTO705 2011-01-22 00:00:00 5 13,9597222805023
MOTO706 2011-01-28 00:00:00 3 0,280277773737907
MOTO704 2011-02-17 00:00:00 6 8,92749977111816
MOTO705 2011-02-09 00:00:00 6 10,07972240448
MOTO703 2011-03-15 00:00:00 1 22,6561107933521
MOTO704 2011-03-11 00:00:00 5 24
MOTO706 2011-01-27 00:00:00 1 9,95361125469208
MOTO703 2011-03-16 00:00:00 6 3,79916667938232
MOTO704 2011-01-08 00:00:00 6 24
但我需要得到这样的结果:
eqmt shiftdate 1 2 3 4 5 6 7
MOTO706 2011-01-28 00:00:00 values for each category
MOTO704 2011-02-17 00:00:00
MOTO705 2011-02-09 00:00:00
MOTO703 2011-03-15 00:00:00
我一直在尝试使用选择语句,但我无法使结构正常工作。