我是靠谱客的博主 安静发卡,最近开发中收集的这篇文章主要介绍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 循环创建列_MySQL在select语句中生成带有循环的列所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部