0
  Sample Gender Handedness
    1   Female  Right-handed
    2   Male    Left-handed
    3   Female  Right-handed
    4   Male    Right-handed
    5   Male    Left-handed
    6   Male    Right-handed
    7   Female  Right-handed
    8   Female  Left-handed
    9   Male    Right-handed
    10  Female  Right-handed

              Left-
             handed    Right-
                       handed Total
    Males      2         3      5
    Females    1         4      5
    Total      3         7      10

使用交叉表,我可以像在第二个表中一样获取第一个表,以使用以下代码获取该表

SELECT gender,
       SUM(CASE WHEN Handedness = 'Left-handed' THEN 1 ELSE 0 END) left_handed,
       SUM(CASE WHEN Handedness = 'Right-handed' THEN 1 ELSE 0 END) right_handed,
       COUNT(*) total
  FROM Table1
 GROUP BY gender WITH ROLLUP

我需要在 html 表中显示在 mysql 中获取的第二个表值,以便在 php 和 codeigniter 中查看。有人可以帮我怎么做谢谢。

4

0 回答 0