我搜索并搜索了这个答案,但我什么都找不到。
目前这是我当前的查询
create TABLE VAR_PEAK
as SELECT a.ID_NO, a.CODE,
a.VAR1 as PKEI_1,
a.VAR2 as PKEI_2,
a.VAR3 as PKEI_3,
b.VAR1 as PKE_1,
b.VAR2 as PKE_2,
b.VAR3 as PKE_3,
c.VAR1 as PKW_1,
c.VAR2 as PKW_2,
c.VAR3 as PKW_3,
d.VAR4 as PKWE_1,
d.VAR4 as PKWE_2,
d.VAR4 as PKWE_3
from LIVE_VARAN a INNER JOIN LIVE_VARAN b ON a.ID_NO=b.ID_NO
INNER JOIN LIVE_VARAN c ON a.ID_NO=c.ID_NO
INNER JOIN LIVE_VARAN d ON a.ID_NO=d.ID_NO
WHERE a.VARIABLE = 'PKEI' AND a.POS = 'DES' AND b.VARIABLE = 'PKE' AND b.POS = 'DES'
AND c.VARIABLE = 'PKW' AND c.POS = 'DES' AND d.VARIABLE = 'PKWE' AND d.POS = 'DES'
这个当前查询只是不运行,它只是永远加载和加载。
数据就像这样
ID_NO VARIABLE POS VAR1 VAR2 VAR3
D55 PKEI MES 4 5 9
D24 PKEI MES 4 5 5
D78 PKE MES 4 3 9
D45 PKE MES 4 5 9
D54 PKWE MES 21 5 9
D45 PKWE MES 4 54 9
D55 PKW MES 9 8 4
D54 PKEI MES 1 1 4
D55 INT CLE 100 100 124
我正在尝试创建的新表格会有像这样的新列标题
ID_NO CODE PKEI_1 PKEI_2 PKEI_3 PKE_1 PKE_2 PKE_3 PKW_1 PKW_2 PKW_3 PKWE_1 PKWE_2 PKWE_3
有人能在查询中发现我的错误吗?
答案 0 :(得分:0)
您正在加入相同的ID:a.ID_NO=b.ID_NO
,a.ID_NO=c.ID_NO
,a.ID_NO=d.ID_NO
和
每条记录只有一个VARIABLE
字段,但您尝试加入a,b,c,d中的行a.VARIABLE = 'PKEI'
和b.VARIABLE = 'PKE'
AND c.VARIABLE = 'PKW'
AND {{ 1}}。怎么可能?
您需要将d.VARIABLE = 'PKWE'
更改为=
<>
,a.ID_NO <> b.ID_NO
,a.ID_NO <> c.ID_NO
a.ID_NO <> d.ID_NO