mysql:11134
From: "ryoozy" <"ryoozy" <ryoozy@xxxxxxxxxx>>
Date: Tue, 8 Mar 2005 01:20:01 +0900
Subject: [mysql 11134] Re: GROUP BY の使い方で
とみたさん、ML皆さんおせわになります。 select article.id,name1,sum(number) as sum1 from article left outer join stock on article.id=stock.article_id group by article.id; で +-----------+-------+-----+ |article_id | name1 | sum1| +-----------+-------+-----+ | 1 | aaaa | 100 | +-----------+-------+-----+ | 2 | bbbb | 200 | +-----------+-------+-----+ | 3 | cccc | NULL| +-----------+-------+-----+ | 4 | dddd | 300 | +-----------+-------+-----+ 願ってた結果を得ることができました。 そこでさらに、テーブルstockにWHEREを適用したくて SELECT article.id, article.name1,SUM(number) AS sum1 FROM article LEFT OUTER JOIN (SELECT * FROM stock WHERE number >150) AS stock ON ( article.id = stock.article_id ) GROUP BY article_id ORDER BY article.id; と書きましたが、結果は +-----------+-------+-----+ |article_id | name1 | sum1| +-----------+-------+-----+ | 1 | aaaa | NULL| +-----------+-------+-----+ | 2 | bbbb | 200 | +-----------+-------+-----+ | 4 | dddd | 200 | +-----------+-------+-----+ こうなりました、 +-----------+-------+-----+ |article_id | name1 | sum1| +-----------+-------+-----+ | 1 | aaaa | NULL| +-----------+-------+-----+ | 2 | bbbb | 200 | +-----------+-------+-----+ | 3 | cccc | NULL| +-----------+-------+-----+ | 4 | dddd | 200 | +-----------+-------+-----+ このような結果を得るにはどのようなSQLを書けばいいのでしょうか よろしくお願いします。 奮闘中http://hdkk.com/notobe/CustomView1list.php ------- 平野
11130 2005-03-07 02:19 ["ryoozy" <ryoozy@xxx] GROUP BY の使い方で 11131 2005-03-07 07:54 ┗[とみたまさひろ <tomm] 11133 2005-03-07 09:39 ┗["ryoozy" <ryoozy@xxx] -> 11134 2005-03-08 01:20 ┗["ryoozy" <ryoozy@xxx] 11137 2005-03-08 06:27 ┗[とみたまさひろ <tomm]