概述
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 循环创建列_MySQL在select语句中生成带有循环的列所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复