SET 和 Select 查询在单个 MySql 查询中组合 运行 以在 pentaho 中传递结果

SET and Select Query combine Run in a Single MySql Query to pass result in pentaho

以下 3 个查询我想 运行 作为 mysql 中的单个查询,我会将此结果传递给 Pentaho 查询组件以绘制一些图形。

SET @input = select "22:4,33:4" from dual;  
SET @count := 0;     
select SUBSTRING_INDEX(@input, ' ', (@count) * 2), ' ', -1) as xyz, som_cnt as count from abc;   

示例字符串的长度未知 (22:4,33:4,96:6....)

expected output 

xyz      count
---------------- 
22        4
33        4
96        6

参考 -

我想要 mysql link 中的相同功能,如下所示 我试过这个解决方案,但我不确定 set_config 是否适用于 mysql。 SET and SELECT within a single query?

或 运行 在 Pentaho 的查询组件中存储过程的任何方法。

您可以将用户定义的会话变量的初始化移动到 Derived table,并且 Cross Join 与您的其他 table(s):

SELECT SUBSTRING_INDEX(@input, ' ', (@count) * 2), ' ', -1) AS xyz, 
       som_cnt AS `count` 
FROM abc
CROSS JOIN (SELECT @count := 0, 
                   @input := '22:4,33:4'
           ) AS user_init_vars