In MySQL I have a function that takes a number argument and spits out a subset of results from another table, based on that number. Implementation currently looks like:
SELECT
id,
date,
function(do stuff with value 1) as t1,
function(do stuff with value 2) as t2,
function(do stuff with value 3) as t3,
...
function(do stuff with value N) as tN
FROM table
Can you use a loop in a select statement (or even a procedure that builds a table) so the above becomes:
SELECT
id,
date,
LOOP x = 1 through N
function(do stuff with value x) as tx,
END LOOP
FROM table
Thanks.
解决方案
yes you can... take a look into DynamicSQL..
In general, you build a string that contains the SQL statement you want to execute, then prepare it, then execute it...
最后
以上就是安静发卡最近收集整理的关于mysql 循环创建列_MySQL在select语句中生成带有循环的列的全部内容,更多相关mysql内容请搜索靠谱客的其他文章。
发表评论 取消回复