首页 > 解决方案 > 从 3 个不同的列中选择不同的记录

问题描述

我有这样的场景。

在此处输入图像描述

有 3 个不同的列。用户 ID、硬币和钱包。如果特定用户有任何硬币和钱包,我只想选择不同的硬币和钱包。我怎样才能做到这一点。在下图中,您可以看到我目前拥有的和想要的。我为此尝试使用子查询,但由于某种原因,它似乎无法正常工作。

标签: mysqlcodeignitersubquerycodeigniter-3

解决方案


您可以尝试使用联合

select userid, coin as asset from tablename where coin is not null
union 
select userid, wallet from tablename where wallet is not null

推荐阅读