1

sql查询:

select
usr.username,
(
  select usr2.username
  from users as usr2
) as another_user
from users as usr
having usr.username != another_user

我如何usr.username与子查询进行比较,例如命名为another_user

我想得到usr.username不等于的所有结果another_user

我尝试了该WHERE子句或HAVING但仍然出现错误

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
4

2 回答 2

0

尝试

select
usr.username,
(
  select username from users where ...
) as another_user
from users as usr
where usr.username <> another_user.username
于 2012-06-08T13:32:20.673 回答
0

也许是这样的:

SELECT
    *
FROM
(
    select
    usr.username,
    (
      ....
    ) as another_user
    from users as usr
) AS T
WHERE
    NOT T.username = T.another_user
于 2012-06-08T13:32:42.477 回答