请我尝试在选择计数(*)上获取关联列值。这是我的代码。
$res = mysql_query("select count(*) as total from table where reg = '12' GROUP BY YEAR DESC LIMIT 7");
while($r4 = mysql_fetch_assoc($res)){
$totalscore = $r4['AVERAGE'];
$len = $r4['total'];
}
$len
返回我的预期值,而AVERAGE列未定义,$totalscore = $r4['AVERAGE'];
AVERAGE是我数据库中的一列。如果我的sql语句是count(*)??这是否意味着我无法获取关联列值?任何想法?
答案 0 :(得分:0)
您没有在查询中选择average
列
您可以选择更多列,如下所示:
SELECT
COUNT(*) as total,
`AVERAGE`
FROM table
WHERE reg = '12'
GROUP BY YEAR DESC
LIMIT 7