我是靠谱客的博主 安静发卡,这篇文章主要介绍mysql 循环创建列_MySQL在select语句中生成带有循环的列,现在分享给大家,希望可以做个参考。

bd96500e110b49cbb3cd949968f18be7.png

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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部