问题描述
我在 unpivot sql 语句上遇到问题,下表是它的样子:
I am facing problem on unpivot sql statement, below is the table how its look like:
我想旋转 A0001、A0002 和 A0003.为 HEADER、SEQUENCE 和 DATA 再创建 3 列.下面是我预期的表格会变成这样:
I want to pivot A0001,A0002 and A0003. Create 3 more column for HEADER,SEQUENCE AND DATA. Below is my expected table to become like this:
下面是我尝试过的sql语句:
Below is the sql statement I have try:
我写的SQL只允许显示pivot后的数据,对于HEADER和SEQUENCE字段我不知道怎么写
The SQL I write only allow to show the data after pivot, for HEADER and SEQUENCE field I have no idea how to write
其次,我还想过滤掉是否有任何枢轴列为零将被过滤掉.例如,ID = S3,A0001 为 0,因此过滤零只得到其他大于零的字段
Secondly, I would also like to filter out if any pivot column is zero will be filter out. Example, ID = S3, A0001 is 0,therefore filter the zero and only get other fields which is greater than zero
推荐答案
应用unpivot后可以有这种情况,如下图-
You can have this condition after appling unpivot as below -
在这种情况下,您可以使用 unvipot
函数,也可以简单地使用 union
,如下所示 -
You can either use the unvipot
function or you can simply use union
also in this case as below -
这篇关于SQL 逆透视表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!