Qlik Sense:左联接两个常驻表

时间:2018-08-31 10:38:58

标签: join left-join qlikview qliksense

我有两个桌子:

violations_details:
LOAD
    "appname",
    "snapshot_id",
    "metric_id",
    "object_id",
    "object_type",
    "object_full_name",
    "metric_num_value",
    "status",
    "module_name",
    "Anz_Fehler",
    "violations_details_kz",
    "error_abs";
SQL SELECT 
    "appname",
    "snapshot_id",
    "metric_id",
    "object_id",
    "object_type",
    "object_full_name",
    "metric_num_value",
    "status",
    "module_name",
    1 as "Anz_Fehler",
    1 as "violations_details_kz",
    CASE WHEN status = 'Added' THEN 1 
         WHEN status = 'Deleted' THEN -1 
         ELSE 0
    END as error_abs
FROM "postgres"."cast_xapp_tools"."datapond_violations_details";

LOAD
    gen_id,
    gen_app,
    gen_patt1,
    gen_patt2,
    gen_class FROM [lib://AttachedFiles/gen_pattern.xlsx] (ooxml, embedded labels, table is tbl_gen_pattern);

现在,我想将coloumn gen_id加入到表violation_details中,其中object_full_name类似于gen_patt1。如果与gen_id不匹配,则violation_details必须为空白。

大小: 表violation_details> 400万行 talbe gen_pattern = 55行

有什么简单的主意吗?我认为我必须在其中使用resident子句,但每次尝试都会失败。

谢谢

2 个答案:

答案 0 :(得分:0)

Violations_details:
LOAD
    "appname",
    "snapshot_id",
    "metric_id",
    "object_id",
    "object_type",
    "object_full_name" as gen_id,
    "metric_num_value",
    "status",
    "module_name",
    "Anz_Fehler",
    "violations_details_kz",
    "error_abs";
SQL SELECT 
    "appname",
    "snapshot_id",
    "metric_id",
    "object_id",
    "object_type",
    "object_full_name",
    "metric_num_value",
    "status",
    "module_name",
    1 as "Anz_Fehler",
    1 as "violations_details_kz",
    CASE WHEN status = 'Added' THEN 1 
         WHEN status = 'Deleted' THEN -1 
         ELSE 0
    END as error_abs
FROM "postgres"."cast_xapp_tools"."datapond_violations_details";

Left join

LOAD
    gen_id,
    gen_app,
    gen_patt1,
    gen_patt2,
    gen_class FROM [lib://AttachedFiles/gen_pattern.xlsx]  (ooxml, embedded labels, table is tbl_gen_pattern);

答案 1 :(得分:0)

您非常亲密-实际上您不必使用resident,因为您可以在加载时立即加入它。 Qlik连接具有相同名称的字段。我不确定您要哪个字段,所以我只是假设object_id与gen_id相同(请注意如何将object_id更改为gen_id的别名)。因此,Qlik现在知道要在该字段上联接表(尽管您可能希望在其他字段上联接表)。

violations_details:
LOAD
    "appname",
    "snapshot_id",
    "metric_id",
    "object_id" as gen_id,
    "object_type",
    "object_full_name",
    "metric_num_value",
    "status",
    "module_name",
    "Anz_Fehler",
    "violations_details_kz",
    "error_abs";
SQL SELECT 
    "appname",
    "snapshot_id",
    "metric_id",
    "object_id",
    "object_type",
    "object_full_name",
    "metric_num_value",
    "status",
    "module_name",
    1 as "Anz_Fehler",
    1 as "violations_details_kz",
    CASE WHEN status = 'Added' THEN 1 
         WHEN status = 'Deleted' THEN -1 
         ELSE 0
    END as error_abs
FROM "postgres"."cast_xapp_tools"."datapond_violations_details";

left join (violations_details)
LOAD
    gen_id,
    gen_app,
    gen_patt1,
    gen_patt2,
    gen_class 
FROM [lib://AttachedFiles/gen_pattern.xlsx] (ooxml, embedded labels, table is tbl_gen_pattern);