1

我在 QlikSense 数据加载编辑器中通过此 SQL 查询加载了如下表格,

[RESOURCE_ALLOCATION]:
select t.rec_id as RESOURCE_ALLOC_TASKID,
t.name as RESOURCE_ALLOC_TASKNAME,
t.actual_starttime as RESOURCE_ALLOC_STARTTIME,
t.actual_endtime as RESOURCE_ALLOC_ENDTIME,
extract(year from t.actual_starttime) as RESOURCE_ALLOC_YEAR,
(t.actual_endtime - t.actual_starttime) as RESOURCE_ALLOC_DAYS,
t.resource_id as RESOURCE_ALLOC_ERSOURCEID,
r.name as RESOURCE_ALLOC_ERSOURCENAME
from public.dsh_project_tasks t, public.dsh_resources r
where t.resource_id = r.rec_id and extract(year from t.actual_starttime) = extract (year from t.actual_endtime);

然后我试图通过在加载数据编辑器中的上面一个查询之后的另一个查询从最后加载的表 [RESOURCE_ALLOCATION] 中选择来加载另一个表,如下所示

[Resource_Utilization]:
load rr.RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename,
          rr.RESOURCE_ALLOC_YEAR as busy_resourceyear,
          Sum(rr.RESOURCE_ALLOC_DAYS) as busy_resourceDays,
          if(Sum(rr.RESOURCE_ALLOC_DAYS) < 368, 'busy', 'free')as BUSY_RESOURCESTATUS
from RESOURCE_ALLOCATION rr
group by rr.RESOURCE_ALLOC_ERSOURCENAME, rr.RESOURCE_ALLOC_YEAR;




[Resource_Utilization]:
load rr.RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename,
rr.RESOURCE_ALLOC_YEAR as busy_resourceyear,
(365 - Sum(rr.RESOURCE_ALLOC_DAYS)) as busy_resourceDays,
if((365 - Sum(rr.RESOURCE_ALLOC_DAYS)) < 366, 'free', 'busy') as BUSY_RESOURCESTATUS
from resource_allocation rr
group by rr.RESOURCE_ALLOC_ERSOURCENAME, rr.RESOURCE_ALLOC_YEAR;

但我在加载数据时出错,说

发生以下错误:无效路径此处发生错误:

[Resource_Utilization]:
load rr.RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename,
rr.RESOURCE_ALLOC_YEAR as busy_resourceyear,
Sum(rr.RESOURCE_ALLOC_DAYS) as busy_resourceDays,
if(Sum(rr.RESOURCE_ALLOC_DAYS) < 368, 'busy', 'free')as BUSY_RESOURCESTATUS 
from RESOURCE_ALLOCATION rr group by rr.RESOURCE_ALLOC_ERSOURCENAME, rr.RESOURCE_ALLOC_YEAR

请帮助,尽管相同的查询在数据库控制台中很好地选择了数据,为什么我会收到此错误?

4

1 回答 1

2

[Resource_Utilization]: load rr.RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename, rr.RESOURCE_ALLOC_YEAR as busy_resourceyear, Sum(rr.RESOURCE_ALLOC_DAYS) as busy_resourceDays, if(Sum(rr.RESOURCE_ALLOC_DAYS) < 368, 'busy', 'free')as BUSY_RESOURCESTATUS from RESOURCE_ALLOCATION rr group by rr.RESOURCE_ALLOC_ERSOURCENAME, rr.RESOURCE_ALLOC_YEAR;

SQL 语法仅在将查询传递到 SQL Server 时才有效。使用结果表时,您需要使用本机 Qlik Sense 脚本语言语法。使脚本正常工作所需要的非常相似;

[Resource_Utilization]:
load RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename,
      RESOURCE_ALLOC_YEAR as busy_resourceyear,
      Sum(RESOURCE_ALLOC_DAYS) as busy_resourceDays,
      if(Sum(RESOURCE_ALLOC_DAYS) < 368, 'busy', 'free') as BUSY_RESOURCESTATUS
resident RESOURCE_ALLOCATION
      group by RESOURCE_ALLOC_ERSOURCENAME, RESOURCE_ALLOC_YEAR;

关键变化是将 FROM 更改为 RESIDENT 以便 Sense 知道查看它自己的结果表,而不是您引用的表的一些外部源。RR。缩写将导致它失败,因为 Sense 每个脚本请求只能引用一个表。

于 2016-08-04T07:51:44.260 回答