php mysql 分组统计问题

2024-12-02 18:25:48
推荐回答(4个)
回答1:

php不懂,
SQL 写给你
SELECT user, SUM(shul) shul FROM h_user GROUP by user

回答2:

$link=mysql_connect(localhost,用户名,密码);//连接mysql数据库
mysql_select_db(mysql数据库名);//选择数据库名
$sql="select user,count(shul) as sumshul from h_user group by user";//定义查询语句
$result=mysql_query($sql);//执行查询
echo "

\n";
while($row=mysql_fetch_array($result,MYSQL_ASSOC)){
echo "\n";//结果以表格内容输出
}
echo "
".$row[user]."".$row[sumshul]."
\n";
mysql_free_result();//清除查询缓存
mysql_close();//关闭mysql连接
?>

回答3:

$sql="select user,sum(shul) from h_user group by user ";
$result=mysql_query($sql);
$arr=mysql_fetch_array($result);
foreach($arr as $k=>$v){
echo $v[0].''.$v[1];
}

回答4:

select user,sum(shul) from h_user group by user