您可以为每个列基于CASE WHEN或IF构建字符串,如果该值大于0,则应进行验证。
例如:
CREATE TABLE test_tbl( id INT NOT NULL AUTO_INCREMENT, col1 INT, col2 INT, col3 INT, PRIMARY KEY ( id ) );insert into test_tbl (col1,col2,col3)values (0,0,0),(8,0,0),(8,null,8),(8,8,8);select *,TRIm(TRAILING ',' FROM concat( if(col1 > 0,'col1,',''), case when col2 > 0 then 'col2,' else '' end, if(col3 > 0,'col3,','') )) as bigger_than_0from test_tblwhere (col1>0 or col2>0 or col3>0);
给出:
id col1 col2 col3 bigger_than_02 8 0 0 col13 8 null 8 col1,col34 8 8 8 col1,col2,col3
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)