gpt4 book ai didi

php - 从所有列中选择不同的值

转载 作者:行者123 更新时间:2023-11-29 20:42:55 27 4
gpt4 key购买 nike

我只想从每列中选择不同的值。没有明显的组合。这是我的查询,但它返回所有列的不同组合。我希望每一列都显示自己不同的值,而不依赖于其他列。

 $sql= "select distinct
CASE WHEN col1 not regexp '[0-9]' THEN col1 else null end as col1
,CASE WHEN col2 not regexp '[0-9]' THEN col2 else null end as col2
,CASE WHEN col3 not regexp '[0-9]' THEN col3 else null end as col3 from table_name";

它返回:

col1| col2| col3
a 1 3
b 2 4
c 2 4
d 1 3

你们可以看到 col2 和 col3 的值并不不同,我也只想与 col2 和 col3 不同。谢谢!

最佳答案

我对你想要的最好的猜测是使用union all:

select distinct (case when col1 not regexp '[0-9]' then col1 end) as col1, 'col1' as which
from table_name
union all
select distinct (case when col2 not regexp '[0-9]' then col2 end) as col2, 'col2' as which
from table_name
union all
select distinct (case when col3 not regexp '[0-9]' then col3 end) as col3, 'col3' as which
from table_name;

这会产生一个包含两列的结果,一列是列名称,另一列是列中的不同值。

关于php - 从所有列中选择不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38543485/

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