【问题标题】:Qlikview CASE statement or subquery inside a load and apply map加载和应用地图中的 Qlikview CASE 语句或子查询
【发布时间】:2015-09-02 12:18:15
【问题描述】:

有一个内联加载,我必须将歌曲 ID 添加到豁免列表:

Exemptsongs:

Load * Inline [
Song ID
45875
65463
43785
90347
23456
89438
16745
];

Exemptsongsmap:
Mapping LOAD
[Song ID],'Exempt' as [Exempt songs exempt]
Resident Exemptsongs;

DROP Table Exemptsongs;

然后在需要时将其加载到播放列表的其他位置。

我想要做的也是添加由特定用户添加的歌曲 ID 以进行豁免,但仅当该用户添加时,其他人添加时它们不会被豁免(除非在豁免列表中特别列出以上)。

我在想(伪)这样的事情:

Exemptsongs:

Load * Inline [
Song ID
45875
65463
43785
90347
23456
89438
16745
(SELECT SongID FROM Songs WHERE addedbyuser = 'MATT')
];

Exemptsongsmap:
Mapping LOAD
[Song ID],'Exempt' as [Exempt songs exempt]
Resident Exemptsongs;

DROP Table Exemptsongs;

那么在加载播放列表时,applymap 部分目前是这样的:

ApplyMap('Exemptsongsmap',[Playlist ID],'Non-exempt') as [Exempt songs exempt],

但是想不到如果songid也是由其他人添加的,如何不让songid免于豁免。

例如

如果用户 matt 添加了歌曲 ID 12345 并且另一个用户添加了它,我希望它在由 matt 添加时在播放列表中被排除。

错误 1:

Syntax error, missing/misplaced FROM:

Exemptsongs:

Load [Song ID]& as UniqueID Inline [
Song ID
45875
65463
43785
90347
23456
89438
16745
]
Exemptsongs:

Load [Song ID]& as UniqueID Inline [
Song ID
45875
65463
43785
90347
23456
89438
16745
]

错误 2:

Field not found - <Song ID>
load [Song ID]&addedbyuser as UniqueID 
from Songs 
where addedbyuser='Matt';

错误 3:

Table not found
Exemptsongsmap:
Mapping LOAD Distinct
UniqueID,'Exempt' as [Exempt songs exempt]
Resident Exemptsongs

错误 4:

Table not found
DROP TABLES statement

然后是我们没有改变的东西的多个其他错误......

【问题讨论】:

    标签: subquery mapping case qlikview


    【解决方案1】:

    您需要创建一个唯一的 ID,即 SongId 和 addedbyuser 连接。 chr(39) 的东西只是创建一个列表,其中每个值都为“值”。

    USERS:
    load concat(distinct addedbyuser,chr(39)&','&chr(39)) as userids from Songs;
    
    let vList = chr(39)&fieldvalue('userids',1)&chr(39);;
    
    for each a in $(vList)
    
    ExemptSongs:
    Load [Song ID]&$(a) as UniqueID; 
    Inline [
    Song ID
    45875
    65463
    43785
    90347
    23456
    89438
    16745
    ];
    
    next a
    
    //Allow auto concatenate of these tables
    load [Song ID]&addedbyuser as UniqueID 
    from Songs 
    where addedbyuser='Matt';
    
    Exemptsongsmap:
    Mapping LOAD distinct
    UniqueID,'Exempt' as [Exempt songs exempt]
    Resident Exemptsongs;
    
    DROP Table Exemptsongs;
    

    最后

    ApplyMap('Exemptsongsmap',[Playlist ID]&addedbyuser,'Non-exempt') as [Exempt songs exempt],
    

    【讨论】:

    • 感谢您的回答,现在将其放入并重新加载所有内容...会让您知道。
    • 错误1;你错过了一个';' UniqueID 之后 内联之前
    • 错误 2;你需要让你的数据匹配,如果你的来源是 SondID 没有空格,我使用 [Song ID],你需要让它们完全匹配。
    • 错误 3&4; Exemptsongs 表不存在,因为先前的错误导致加载失败,因此修复其他错误应该可以解决此问题。
    • OK 错误 1,应该是这个样子?...Load [Song ID]&amp;$(a) as UniqueID; Inline [ ?
    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 2014-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 1970-01-01
    相关资源
    最近更新 更多