我想要显示一个输出表,用于统计在表中找到的所有用户。 基本上我想输出的样子:Mysql为不同的where子句显示不同的列
+-----------+-----------+
| user1 | user2 |
+-----------+-----------+
| 5 | 2 |
+-----------+-----------+
我只是用一个虚表来进行测试。我的查询是这样的:
(
select
name as user1
from
users
where
name = 'root'
) UNION (
select
name as user2
from
users
where
name = 'not_root'
)
其中仅输出是这样的:
+-----------+
| user1 |
+-----------+
| 5 |
| 2 |
+-----------+
这其实给我的我正在找的答案。你能否为此添加一些描述?我想明白为什么会发生这种情况,因为我是一个新手。 – clueless 2014-10-21 02:05:32
另外,我不能让'count(u1。*)'工作(语法错误),我不得不使用'count(u1.name)'。 – clueless 2014-10-21 02:06:41
@DumbAsker确实看起来像count(u1。*)不起作用。我使用相同的方法改进了查询并添加了另一个。 – triclosan 2014-10-21 08:41:42