博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql刷MPP建表语句
阅读量:6125 次
发布时间:2019-06-21

本文共 2484 字,大约阅读时间需要 8 分钟。

代码实例

SELECT table_schema    ,table_name    ,(        CASE             WHEN ORDINAL_POSITION = mincol                AND ORDINAL_POSITION < maxcol                THEN CONCAT (                        "create  table if not exists"                        ,table_schema                        ,"."                        ,table_name                        ,"(`"                        ,column_name                        ,"` "                        ,COLUMN_TYPE                        ,","                        )            WHEN ORDINAL_POSITION = mincol                AND ORDINAL_POSITION = maxcol                THEN CONCAT (                        "create  table if not exists"                        ,table_schema                        ,"."                        ,table_name                        ,"(`"                        ,column_name                        ,"` "                        ,COLUMN_TYPE                        ,");"                        )            WHEN ORDINAL_POSITION > mincol                AND ORDINAL_POSITION < maxcol                THEN CONCAT (                        "`"                        ,column_name                        ,"` "                        ,COLUMN_TYPE                        ,","                        )            WHEN ORDINAL_POSITION = maxcol                THEN CONCAT (                        "`"                        ,column_name                        ,"` "                        ,COLUMN_TYPE                        ,");"                        )            END        ) AS statement    ,ORDINAL_POSITION    ,maxcol    ,mincolFROM (    SELECT b.table_schema,b.table_name,b.ORDINAL_POSITION,b.column_name,    (case    when column_type = 'timestamp' then 'datetime'    when column_type = 'bit(1)' then 'int(1)'    else        column_type    end ) AS column_type        ,a.maxcol        ,a.mincol    FROM (        SELECT table_schema            ,table_name            ,max(ORDINAL_POSITION) maxcol            ,min(ORDINAL_POSITION) mincol        FROM information_schema.COLUMNS        GROUP BY table_schema            ,table_name        ) a    JOIN (        SELECT table_schema            ,table_name            ,ORDINAL_POSITION            ,column_name            ,COLUMN_TYPE        FROM information_schema.COLUMNS        ORDER BY table_schema            ,table_name            ,ORDINAL_POSITION ASC        ) b ON a.table_schema = b.table_schema        AND a.table_name = b.table_name    ) cWHERE table_schema = 'test'

转载地址:http://xlwua.baihongyu.com/

你可能感兴趣的文章
类斐波那契数列的奇妙性质
查看>>
配置设置[Django]引入模版之后报错Requested setting TEMPLATE_DEBUG, but settings are not configured....
查看>>
下一步工作分配
查看>>
Response. AppendHeader使用大全及文件下载.net函数使用注意点(转载)
查看>>
Wait Functions
查看>>
代码描述10313 - Pay the Price
查看>>
jQuery最佳实践
查看>>
centos64i386下apache 403没有权限访问。
查看>>
vb sendmessage 详解1
查看>>
jquery用法大全
查看>>
Groonga 3.0.8 发布,全文搜索引擎
查看>>
PC-BSD 9.2 发布,基于 FreeBSD 9.2
查看>>
网卡驱动程序之框架(一)
查看>>
css斜线
查看>>
Windows phone 8 学习笔记(3) 通信
查看>>
重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush
查看>>
Revit API找到风管穿过的墙(当前文档和链接文档)
查看>>
Scroll Depth – 衡量页面滚动的 Google 分析插件
查看>>
Windows 8.1 应用再出发 - 视图状态的更新
查看>>
自己制作交叉编译工具链
查看>>