SET @Efields := '';
SET @Esql:='';
SET @Table_Name = 'table1';
select @Efields := GROUP_CONCAT(COLUMN_NAME SEPARATOR ' IS NOT NULL AND ')
from information_schema.columns
where TABLE_NAME = @Table_Name;
SELECT @Esql:=CONCAT('select * from ',@Table_Name ,' WHERE ',@Efields,' IS NOT NULL ');
PREPARE stmt1 FROM @Esql;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
2条答案
按热度按时间qnzebej01#
你可以试着从
information_schema.columns
然后执行表dynamic sql
.这样地。
sqlfiddle:https://www.db-fiddle.com/f/32pise5bchksvpzk6ljep3/0
5fjcxozz2#
如果需要,可以在where子句中执行以下操作(假设表中的列数为10):