有表:
我需要获取具有“列”指定值的非空列。
试试这个
select * from table where category='1-137-2891' and defence is not null and type is not null
但显然得到了空集。
我想我已经为你找到了答案。
假设你有这样的表:
create table t (a int, b int);
insert into t (a, b) values (1, null);
然后,您可以创建动态 SQL 语句并使用 EXECUTE 命令执行它;
set @sql = (select concat('select ',
case when sum(a) is null then '' else 'A' end,
case when sum(b) is null then '' else ', ' end,
case when sum(b) is null then '' else 'B' end,
' from t')
from t);
prepare stmt FROM @sql;
execute stmt;
deallocate prepare stmt;
SELECT * FROM table WHERE ('data1' 不为空)