从sql到qlik查看声明变量

时间:2016-12-20 18:40:27

标签: sql-server

我是QV的新手,在将此查询转移到QV时遇到问题。我做错了什么?

count(case when interaction=1 then 1 end) as clicks

1 个答案:

答案 0 :(得分:0)

您是否设法解决了问题? 据我所知,它不可能使用 SQL SET 命令,因为在Qlik中我们已经有一个 SET 命令,它与SQL命令有很大不同。
我建议先执行第一个查询,检索 max(Id),然后将其传递给变量,然后使用该参数进行第二次查询。

即。

//execute the first query and retrieve the max Id
FirstQuery:
SQL
SELECT
    max(Id) as maxId
FROM
    schema.table;

//retrieve the value from the previous query and pass it to a variable
let vMaxId = fieldvalue('maxId', 1);

//execute the second query and use the variable in the where clause
SecondQuery:
SQL
SELECT
    *
FROM
    schema.table
WHERE
    Field = $(vMaxId);

另外,请看一下FieldValue function如何运作