gpt4 book ai didi

MySQL:仅获取非空列

转载 作者:行者123 更新时间:2023-11-30 23:11:33 24 4
gpt4 key购买 nike

有表:

enter image description here

我需要获取具有“列”指定值的非空列。

试试这个

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;

Here is an example

关于MySQL:仅获取非空列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19542508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com