初めまして。SQL の勉強をしています。
sql
1CREATE TABLE Table1 2 (`name` varchar(5), `price` int, `foo_id` int) 3; 4 5INSERT INTO Table1 6 (`name`, `price`, `foo_id`) 7VALUES 8 ('apple', 5, 1), 9 ('apple', 20, 1), 10 ('apple', 10, 2), 11 ('apple', 30, 2), 12 ('grape', 10, 1), 13 ('grape', 30, 1), 14 ('grape', 60, 1), 15 ('grape', 50, 2) 16;
というデータがある時に、name でグルーピングした後に foo_id = 1
の価格が最大の値を取り出したく、以下のクエリを書いたのですが、上手くいきません。何が原因なのでしょうか..?
sql
1select * from (select * from Table1 order by price desc) Table1 where foo_id = 1 group by name
結果
name price foo_id apple 20 1 grape 30 1
再現のリンクです。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。