1
は、私はこの結果を得た後、このクエリPDOで2列の値でグループ化された連想配列をフェッチする方法はありますか?
$sql = "
SELECT cls
, sctn
, COUNT(case when gender='M' then 1 end) boys
, COUNT(case when gender='F' then 1 end) girls
FROM student_table
WHERE active = 1
group
by cls
, sctn";
$stmt->query($sql)->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
を実行
Array
(
[1st] => Array(
[0] => Array (
[sctn] => A
[boys] => 8
[girls] => 7
)
[1] => Array (
[sctn] => B
[boys] => 5
[girls] => 4
)
)
[2nd] => Array (
[0] => Array (
[sctn] => A
[boys] => 3
[girls] => 7
)
[1] => Array (
[sctn] => B
[boys] => 8
[girls] => 5
)
)
[3rd] => Array (
[0] => Array (
[sctn] => A
[boys] => 9
[girls] => 11
)
[1] => Array (
[sctn] => B
[boys] => 5
[girls] => 17
)
)
)
が、私は期待していた結果は
ここArray
(
[1st] => Array(
[A] => Array (
[boys] => 8
[girls] => 7
)
[B] => Array (
[boys] => 5
[girls] => 4
)
)
[2nd] => Array (
[A] => Array (
[boys] => 3
[girls] => 7
)
[B] => Array (
[boys] => 8
[girls] => 5
)
)
[3rd] => Array (
[A] => Array (
[boys] => 9
[girls] => 11
)
[B] => Array (
[boys] => 5
[girls] => 17
)
)
)
私はクラスが賢明とセクションカウントしたいです賢く性別が賢明です
私はsctn値も入れ子配列のキー
私のSELECT
クエリに基づいてこの結果を得る方法はありますか?