要以水平方式显示的数据库值 [英] Database values to be display in horizontal

查看:79
本文介绍了要以水平方式显示的数据库值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有3个字段的数据库值,我将这些字段导出到Excel工作表,

我得到了导出的代码excel sheet,但我需要修改导出excel表,



1. excel表的输出需要删除数据库的重复值,如果报警有alarm1,alarms2然后这个值显示在行上





站点节点警报



AB报警1

AB报警1

A c报警2

AB报警2



excel表的输出应该是





站点节点报警A报警B报警C



AB报警1报警2

A c报警2

Hi

I have Database values with 3 fields, Im exporting this fields to Excel sheet,
I got the code to export to excel sheet, But I need modification in exporting the excel sheet,

1. The output of the excel sheet need to remove duplicates values for database and if the alarms having alarms1, alarms2 then this values show on rows


Site Node Alarms

A B alarms1
A B alarms1
A c alarms2
A B alarms2

Output of excel sheet should be


Site Node AlarmsA AlarmsB AlarmC

A B alarms1 alarms2
A c alarms2

推荐答案

您所需要的只是名为 Pivot [ ^ ]。



All you need is called Pivot[^].

SELECT Site, [alarm1],[alarm2],[alarm3]
FROM (
    SELECT Site, [Node], Alarms
    FROM TableName
    ) AS DT
PIVOT(MAX(Alarms) FOR [Node] IN([alarm1],[alarm2],[alarm3])) AS PT





结果如下:



Result should looks like:

Site B       C
A    Alarms1  NULL
A    Alarms2  NULL
A    NULL    Alarms2





请注意,无法以数据方式转移数据你想要的。



Note that there is no way to pivot data the way you want.


这篇关于要以水平方式显示的数据库值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆