我正在尝试计算/分组表中的25列。我使用...一次计算一列的成功率。
//COUNT OFF
$sql = "SELECT count(q1) as count, q1 FROM results GROUP BY q1";
$stmt = $db->prepare($sql);
$stmt->execute();
$firstResults = $stmt->fetchAll();
$sql = "SELECT count(q2) as count, q2 FROM results GROUP BY q2";
$stmt = $db->prepare($sql);
$stmt->execute();
$secondResults = $stmt->fetchAll();
$sql = "SELECT count(q3) as count, q3 FROM results GROUP BY q3";
$stmt = $db->prepare($sql);
$stmt->execute();
$thirdResults = $stmt->fetchAll();
$firstResults = json_encode($firstResults);
$secondResults = json_encode($secondResults);
$thirdResults = json_encode($thirdResults);
..这适用于几列。对于同一个表中的25列,似乎应该有一种重复性较低的方法。我从哪里开始?