2

我有一个这样的 MySQL 脚本:

SELECT ... FROM ... WHERE ...
UNION ALL
SELECT ... FROM ... WHERE ...

现在如何从联合结果中再次选择?

这不起作用:

SELECT * FROM (
    SELECT ... FROM ... WHERE ...
    UNION ALL
    SELECT ... FROM ... WHERE ...
);
4

2 回答 2

7

您需要为内部查询设置一个别名:

SELECT * FROM (
    SELECT ... FROM ... WHERE ...
    UNION ALL
    SELECT ... FROM ... WHERE ...
) as something;
于 2013-02-17T16:14:30.283 回答
0

我想你在问这个:

   SELECT * FROM (
      SELECT ... FROM ... WHERE ...
      UNION ALL
      SELECT ... FROM ... WHERE ...
    )
    WHERE ...
于 2013-02-17T16:09:26.780 回答