mysql的GROUP_CONCAT函数,以及查询表字段语句,以及存储过程调试(在group_concat中可以进行排序操作!!)

1.GROUP_CONCAT函数:用于字段拼接比较合适,类似于foreach标签

 SELECT
    GROUP_CONCAT( NAME ORDER BY sex DESC SEPARATOR ',' ) 
FROM
    beauty

2.GROUP_CONCAT使用前和使用后对比

2.1使用前

    select distinct COLUMN_NAME  from information_schema.COLUMNS 
WHERE
column_name not in ('name') and
    table_name = 'beauty' 
    AND table_schema = 'girls';

2.2使用后:

 select group_concat(distinct COLUMN_NAME order by COLUMN_NAME ASC separator ',') from information_schema.COLUMNS 
WHERE
column_name not in ('name') and
    table_name = 'beauty' 
    AND table_schema = 'girls';
    

3.实战参考的

   begin
                                #查询该表的所有列用于拼接SQL
                                SET group_concat_max_len=102400;
                                select group_concat(distinct COLUMN_NAME order by COLUMN_NAME ASC separator ',')  into colName from `information_schema`.`COLUMNS` 
                                where TABLE_NAME  = c_a01_TblCod and COLUMN_NAME NOT IN('A00','RECORDID','T0196','T0196_01TIME') and table_schema = 'qyrlzy_avic_talent';
            end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值