サブクエリとJOINしたSQL文があるとき、 例) SELECT t1.field1, t2.field2 FROM table1 AS t1 INNER JOIN (SELECT field1, field2 SUM(field3) FROM table2) AS t2 ON t1.field1=t2.field1 サブクエリ内のSUM(field3)も親クエリで使用したい場合は、サブクエリ内の集計項目にも別名を付けて[サブクエリの別名].[フィールドの別名]と記述する。 SELECT t1.field1, t2.field2, t2.total FROM table1 AS t1 INNER JOIN (SELECT field1, field2 SUM(field3) AS total FROM table2) AS t2 ON t1.field1=t2.field1 という感じ
![サブクエリをJOINしたクエリでサブクエリ内の集計項目を親クエリに表示させる - 酔いどれLinux狂[マニア]](https://cdn-ak-scissors.b.st-hatena.com/image/square/e7f0100fc9ee40878227e79c1efd3cfde4e4b41c/height=288;version=1;width=512/http%3A%2F%2Fo-mita.cocolog-nifty.com%2F.shared-cocolog%2Fnifty_managed%2Fimages%2Fweb%2Fogp%2Fdefault.png)