これも、リスト7のクエリを簡単に修正するだけで対応できます(リスト8)。 リスト8 表頭:年齢階級・性別、表側:部署(小計・合計あり) SELECT dept, COUNT(*), SUM(CASE WHEN age <= 30 THEN 1 ELSE 0 END) AS "若手(計)", SUM(CASE WHEN age <= 30 AND sex = '男' THEN 1 ELSE 0 END) AS "若手(男)", SUM(CASE WHEN age <= 30 AND sex = '女' THEN 1 ELSE 0 END) AS "若手(女)", SUM(CASE WHEN age >= 31 THEN 1 ELSE 0 END) AS "ベテラン(計)", SUM(CASE WHEN age >= 31 AND sex = '男' THEN 1 ELSE 0 END)