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

吃可爱长大的小学妹 提交于 2019-12-13 02:21:34

问题


Below 3 queries i want to run as single query in mysql and i will pass this result to Pentaho query component to plot some graph.

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;   

Sample string is of unknown length (22:4,33:4,96:6....)

expected output 

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

reference - Mysql Query to Separate space delimited String Convert into 2 columns

  • Set query count=0, If i can Merge this SET query in select query that is also ok.
  • Select query doing some parsing on input string using count - just sample substring is added. (parsing logic is added here)

I want same functionality in mysql link shown below i tried this solution but i am not sure is set_config works in mysql. SET and SELECT within a single query?

or any method to run store procedure in Query component of Pentaho.


回答1:


You can move the initialization of user-defined session variables to a Derived table, and Cross Join with your other 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 


来源:https://stackoverflow.com/questions/52924507/set-and-select-query-combine-run-in-a-single-mysql-query-to-pass-result-in-penta

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!