mysql> (select total from stats_1.2013_04)
    -> union
    -> (select total from stats_2.2013_04);
+---------+
| total   |
+---------+
| 1856818 |
|      45 |
+---------+
2 rows in set (0.02 sec)
mysql> select sum(total)
    -> from (
    -> select total from stats_1.2013_04
    -> union
    -> select total from stats_2.2013_04
    -> )as x;
+------------+
| sum(total) |
+------------+
|    1856863 |
+------------+
1 row in set (0.02 sec)
*요점. union을 이용하여 select 절에 함수를 사용한다면 맨 마지막에 alias를 붙여준다.
출처: http://stackoverflow.com/questions/3436009/every-derived-table-must-have-its-own-alias-error
'Dev > MySQL' 카테고리의 다른 글
| 조인(Join) (0) | 2013.05.21 | 
|---|---|
| 쿼리튜닝 : EXPLAIN (0) | 2013.05.16 | 
| MySQL Federated : 다른 서버 DB의 테이블 조인하기 (0) | 2013.05.07 | 
| Mysql Replication 개념 (0) | 2013.05.03 | 
| MySQL Replication 설정 (0) | 2013.05.03 |