[前][次][番号順一覧][スレッド一覧]

mysql:14833

From: HIRATSUKA Sadao <HIRATSUKA Sadao <hiratsuka.sadao@xxxxxxxxxx>>
Date: Thu, 07 May 2009 12:21:04 +0900
Subject: [mysql 14833] Re: テーブルごとの合計を求めるには

平塚です。

渡辺さんとは別の案です。
とくにひねりはないですが・・・

On Thu, 07 May 2009 11:35:05 +0900
柴垣 <akiro@xxxxxxxxxx> wrote:

> 求めたい結果セット
> Name  UriageGokei  NyukinGokei
> A           3000          4000
> B           6000          7000

select T.name, UG.UriageGokei, NG.NyukinGokei
from
T
left outer join
(select name, sum(kingaku) UriageGokei from U group by name) UG
on T.name = UG.name
left outer join
(select name, sum(kingaku) NyukinGokei from N group by name) NG
on T.name = NG.name
;

+------+-------------+-------------+
| name | UriageGokei | NyukinGokei |
+------+-------------+-------------+
| A    |        3000 |        4000 |
| B    |        6000 |        7000 |
+------+-------------+-------------+
2 rows in set (0.00 sec)

-- 
平塚貞夫 hiratsuka.sadao@xxxxxxxxxx


[前][次][番号順一覧][スレッド一覧]

     14831 2009-05-07 11:35 [柴垣 <akiro@xxxxxxxx] テーブルごとの合計を求めるには          
     14832 2009-05-07 11:50 ┣[Shuji Watanabe <shuj]                                       
->   14833 2009-05-07 12:21 ┗[HIRATSUKA Sadao <hir]                                       
     14835 2009-05-08 00:42  ┗[柴垣 <akiro@xxxxxxxx]                                     
     14836 2009-05-08 02:00   ┗[ユウシステム 糸瀬 <i]                                   
     14837 2009-05-08 09:42    ┗[柴垣 <akiro@xxxxxxxx]                                 
     14838 2009-05-08 10:00     ┗[Shuji Watanabe <shuj]                               
     14839 2009-05-08 10:59      ┗[ユウシステム 糸瀬 <i]