我在Qlik有这样的转变
abc:
SELECT distinct
AA.ACCOUNT_ID AS ACCOUNT_ID_AA,
AA.ID AS ID_AA,
AA.F_a AS F_a_AA,
AA.F_b AS F_b_AA,
AA.F_c AS F_c_AA,
AA.F_d AS F_d_AA,
AA.F_e AS F_e_AA,
AA.F_f AS F_f_AA,
AA.F_g AS F_g_AA,
AA.P_A_ID AS P_A_ID_AA,
AA.U_P_A_ID AS U_P_A_ID_AA,
AA.A_C AS A_C_AA,
AA.R AS R_AA,
AA.F_h__C AS F_h__C_AA,
AA.I AS I_AA,
AA.L AS L_AA
FROM $(vdb).A AA
;
left join (abc)
LOAD distinct
ACCOUNT_ID_AA AS P_ACCOUNT_ID_AA,
F_a_AA AS P_a_AA,
F_b_AA AS P_b_AA,
F_c_AA AS P_c_AA,
F_d_AA AS P_d_AA,
F_e_AA AS P_e_AA,
F_f_AA AS P_f_AA,
F_g_AA AS P_g_AA
Resident abc;
left join (abc)
LOAD distinct
ACCOUNT_ID_AA AS U_P_ACCOUNT_ID_AA,
F_a_AA AS U_P_a_AA,
F_b_AA AS U_P_b_AA,
F_c_AA AS U_P_c_AA,
F_d_AA AS U_P_d_AA,
F_e_AA AS U_P_e_AA,
F_f_AA AS U_P_f_AA,
F_g_AA AS U_P_g_AA
Resident abc;
你能解释一下它的目的是什么吗?处理一些层次结构之间的关系?
第二个问题是qlik加入。它是如何加入的呢?有人可以向我展示这个关于 PostgreSQL 或任何其他 SQL 语言的示例吗?我唯一知道的是 Qlik 按同名的列进行连接。那么这意味着 SQL 连接将在“ON”部分中包含所有列名称?
我无法弄清楚这背后的逻辑。
令人困惑的部分是上面的脚本中没有“正常”连接。我所说的“正常”是指没有共同的领域可以加入。这就是在 Qlik 中创建交叉联接的方法 - 只需联接两个没有公共字段的表,Qlik 就会创建多对多关系。
如果我简化脚本并加载帐户和多一个字段:
abc:
Load * Inline [
ACCOUNT_ID_AA, F_a_AA
1 , ABC
2 , DEF
3 , GHI
];
left join (abc)
LOAD
ACCOUNT_ID_AA as P_ACCOUNT_ID_AA,
F_a_AA as P_a_AA
Resident
abc
;
left join (abc)
LOAD
ACCOUNT_ID_AA as U_P_ACCOUNT_ID_AA,
F_a_AA as U_P_a_AA
Resident
abc
;
然后当选择一个帐户ID时,结果将是:
你是对的。 Qlik 将根据公共字段自动连接表(区分大小写)。例如(伪代码):
TableName:
Select
AccountID,
CustomerID
TransactionDate
From
Some_DB_Table
;
left join (TableName)
// TableName is optional here
// if not specified Qlik will assume
// that the table above is the one to join to
Select
AccountID,
CustomerID
OrderDate
From
Another_DB_Table
;
将等于以下 SQL:
SELECT s.AccountID AS AccountID,
s.CustomerID AS CustomerID,
s.TransactionDate AS TransactionDate,
c.OrderDate AS OrderDate
FROM Some_DB_Table s
LEFT OUTER JOIN Another_DB_Table a
ON s.AccountID = a.AccountID
AND s.CustomerID = c.CustomerID;