89827


# 実行したい事

最年長が50歳以上かつ最年少が30歳以下の国を表示させてください。

[![Image from
Gyazo](https://i.gyazo.com/a2773173e381f5f499bcacdeec7d50ce.png)](https://gyazo.com/a2773173e381f5f499bcacdeec7d50ce)

# 現状

返り値が空になってしまい、MAX、MINが写真通りに表示されません。  
分かる方居ましたらお願い致します。  
[![Image from
Gyazo](https://i.gyazo.com/4e530e043fb88e36faf1758cb002d6ee.png)](https://gyazo.com/4e530e043fb88e36faf1758cb002d6ee)

# 現状コード

[code]

    SELECT 
    age 
    FROM
    celebrities
    WHERE 
    age >= 50 AND age <= 30;
    
[/code]

celebrities テーブル

[code]

    -- テーブルのデータのダンプ `celebrities`
    --
    
    INSERT INTO `celebrities` (`id`, `name`, `country_code`, `birth`, `age`, `occupation`) VALUES
    (1, 'Emma Charlotte Duerre Watson', 'FRA', '1990-04-15 00:00:00', 31, 'actor'),
    (2, 'Johnny Depp', 'USA', '1963-06-09 00:00:00', 58, 'actor'),
    (3, 'Jim Carrey', 'USA', '1962-01-17 00:00:00', 59, 'actor'),
    (4, 'Daniel Radcliffe', 'GBR', '1989-07-23 00:00:00', 32, 'actor'),
    (5, 'Morgan Freeman', 'USA', '1937-06-01 00:00:00', 84, 'actor'),
    (6, 'Hugh Jackman', 'AUS', '1968-10-12 00:00:00', 53, 'actor'),
    (7, 'Natalie Portman', '', '1981-06-09 00:00:00', 40, 'actor'),
    (8, 'Pierce Brosnan', 'FRA', '1960-10-15 00:00:00', 61, 'actor'),
    (9, 'Sean Connery', 'PER', '1980-05-05 00:00:00', 41, 'singer'),
    (10, 'Dwayne Johnson', 'USA', '1978-12-15 00:00:00', 43, 'fighter'),
    (11, 'Jackie Chan', 'USA', '1992-04-15 00:00:00', 29, 'fighter'),
    (12, 'Adam Sandler', 'FRA', '1976-02-05 00:00:00', 45, 'singer'),
    (13, 'Scarlett Johansson', 'AUT', '1966-01-10 00:00:00', 55, 'model'),
    (14, 'Heath Ledger', 'USA', '1971-10-15 00:00:00', 50, 'actor'),
    (15, 'Edward Norton', 'GBR', '1988-03-12 00:00:00', 33, 'actor'),
    (16, 'Keira Knightley', 'GBR', '1980-11-10 00:00:00', 41, 'model'),
    (17, 'Bradley Cooper', 'USA', '1979-08-01 00:00:00', 42, 'fighter'),
    (18, 'Will Ferrell', 'USA', '1966-01-15 00:00:00', 53, 'comedian'),
    (19, 'Julia Roberts', 'GRC', '1964-09-01 00:00:00', 55, 'actor'),
    (20, 'Daniel Craig', 'USA', '1977-12-09 00:00:00', 44, 'actor'),
    (21, 'Ian McKellen', '', '1998-04-15 00:00:00', 23, 'singer'),
    (22, 'Samuel L. Jackson', 'USA', '1960-04-09 00:00:00', 61, 'actor'),
    (23, 'Ben Stiller', 'BRA', '1964-10-15 00:00:00', 57, 'actor'),
    (24, 'Tommy Lee Jones', '', '1970-09-05 00:00:00', 51, 'comedian'),
    (25, 'Antonio Banderas', 'USA', '1958-10-05 00:00:00', 63, 'actor'),
    (26, 'Denzel Washington', 'USA', '1990-10-25 00:00:00', 31, 'model'),
    (27, 'Steve Carell', 'USA', '1991-02-14 00:00:00', 30, 'actor'),
    (28, 'Shia LaBeouf', 'CHL', '1991-10-05 00:00:00', 30, 'actor'),
    (29, 'Megan Fox', 'GRC', '1992-09-23 00:00:00', 29, 'actor'),
    (30, 'James Franco', 'USA', '1955-04-15 00:00:00', 66, 'actor'),
    (31, 'Mel Gibson', 'COL', '1967-03-08 00:00:00', 54, 'singer'),
    (32, 'Vin Diesel', 'USA', '1982-11-15 00:00:00', 39, 'singer'),
    (33, 'Tim Allen', 'ISL', '1962-02-10 00:00:00', 59, 'actor'),
    (34, 'Kevin Spacey', 'USA', '1990-04-15 00:00:00', 31, 'actor'),
    (35, 'Jason Biggs', 'USA', '1979-03-25 00:00:00', 42, 'actor'),
    (36, 'Seann William Scott', 'USA', '1957-02-22 00:00:00', 64, 'actor'),
    (37, 'Jean-Claude Van Damme', 'USA', '1997-01-10 00:00:00', 24, 'model'),
    (38, 'Zach Galifianakis', 'USA', '1969-04-22 00:00:00', 52, 'actor'),
    (39, 'Owen Wilson', 'USA', '1988-06-05 00:00:00', 31, 'actor'),
    (40, 'Christian Bale', 'USA', '1977-12-01 00:00:00', 44, 'actor'),
    (41, 'Peter Jackson', 'USA', '1994-10-25 00:00:00', 27, 'model'),
    (42, 'Sandra Bullock', 'CUA', '1975-07-19 00:00:00', 46, 'actor'),
    (43, 'Drew Barrymore', 'USA', '1993-06-05 00:00:00', 28, 'singer'),
    (44, 'Macaulay Culkin', 'ESP', '1981-07-22 00:00:00', 40, 'comedian'),
    (45, 'Bill Murray', 'USA', '1988-03-09 00:00:00', 33, 'actor'),
    (46, 'Sigourney Weaver', 'FIN', '1954-12-10 00:00:00', 67, 'actor'),
    (47, 'Jake Gyllenhaal', '', '1990-05-05 00:00:00', 31, 'model'),
    (48, 'Jason Statham', 'USA', '1986-06-08 00:00:00', 35, 'actor');
    
[/code]


CC BY-SA 4.0
2022-07-07T09:08:44.373
89809
2022-07-08T05:06:38.740
2022-07-08T05:06:38.740
53417
53417
question
mysql sql
50歳以上かつ30歳以下が表示できない。


問題文に関連する教材において、`group
by`によるグループ化について`min`や`max`などの集計関数の値を条件式とする場合は`where`句ではなく`having`句を使う旨が書かれていると思います。

おそらく下記のSQLが回答例になります。  
参考にしながら教材を確認してみてください。

※そして他の人の役に立つように質問文を書き直していただけると嬉しいです。

[code]

    select   country_code, max(ce.age), min(ce.age)
    from     celebrities ce
    group by country_code
    having   max(ce.age) >= 50
    and      min(ce.age) <= 30
    
[/code]

[DB Fiddle](https://www.db-fiddle.com/f/6gQVxSAHDHefTygQm5kq7P/0)


CC BY-SA 4.0
2022-07-08T01:41:55.107
89827
2022-07-08T01:41:55.107
9820
89809
answer