mysql动态展示列_mysql 中动态显示列

这是我在工作中的语句,功能是实现动态显示列并且实现查找功能,请大家多多指教!

/*1*/

set group_concat_max_len=8000;

/*2动态获取产品列-用于显示*/

select concat('',

group_concat('',b.objjc,''),'') `FieldList`

from gwpuser_filefields b

where b.visible='1' and b.parentid=1

order by b.objorder asc;

/*3动态获取列*/

select @fieldname:=concat(group_concat('a.'

,lower(b.objname)

,' `'

,CASE WHEN ifnull(b.YESNO,'0')='1' THEN concat('ORD_',b.objjc,'') ELSE b.objjc END

,'`')

)

from gwpuser_filefields b

where b.visible='1' and b.parentid=1 and b.objid<>1

order by b.objorder asc

;

/*4列替换列的显示,超链接*/

select @fieldsql:=concat(

replace(

replace(replace(replace(replace(

replace(replace(replace(

replace(@fieldname

,'a.filetitle','concat('''',ifnull(a.filetitle,''''),'''')')

,'a.filepic','concat('''')')

,'a.tphoto','concat('''')')

,'a.mphoto','concat('''')')

,'a.yesno','case when a.yesno=''1'' then ''是'' else ''否'' end ')

,'a.isnew','case when a.isnew=''1'' then ''新'' else ''老'' end ')

,'a.cancomment','case when a.cancomment=''1'' then ''是'' else ''否'' end ')

,'a.isstock','case when a.isstock=''1'' then ''有货'' else ''无货'' end ')

,'a.prodprice',' round(a.ProdPrice,2)'

)

,

',concat(''修改'') as `修改`'

,',concat(''删除'') as `删除`') `Result`;

/*5表*/

select @fromsql:=' from gwpuser_fileinfo a ';

/*6条件*/

select @wheresql:=case when '$HTTP[FieldName]'<>'' then ' where a.filetype=''G''

and a.objid<>1 and a.parentid=''$HTTP[parentid]''

and ($HTTP[FieldName] like ''$HTTP[key]%''

or ''$HTTP[key]''='''')'

else 'where a.filetype=''G''

and a.objid<>1 and a.parentid=''$HTTP[parentid]''' end

;

/*7排序*/

select @ordersql:=' order by a.objorder';

/*8总条数*/

select @count:=count(*),case when count(*)='0' then '没有记录' else concat('记录数[ ',count(*),' ]条') end `rows`

from gwpuser_fileinfo a

where a.filetype='G'

and a.objid<>1 and a.parentid='$HTTP[parentid]'

and ( instr('$HTTP[FieldName]','$HTTP[key]')>0 or '$HTTP[key]'='')

;

/*9总语句*/

select @sql:=concat('select @count `PAG_NUM`,',ifnull(@fieldsql,''),ifnull(@fromsql,''),ifnull(@wheresql,''),'$HTTP[saf_dgorder]',' limit 0,200;') `Result`;

/*10*/

PREPARE sqlstr FROM @sql;

/*11*/EXECUTE sqlstr ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值