Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 来自多行MYSQL的评论总数_Php_Mysql_Sum - Fatal编程技术网

Php 来自多行MYSQL的评论总数

Php 来自多行MYSQL的评论总数,php,mysql,sum,Php,Mysql,Sum,我必须根据评论对电影进行分类,所以。。我尝试了一些东西,但失败了 嗯 我有两张桌子 1-电影 id -- name 1 XX 2 YY 2集 id -- name 1 XX 2 YY mid->来自第一个表的电影id eid->剧集id id -- mid -- eid -- comments 1 1 1 4 2 1 2 2 3 1 3 2 4 2

我必须根据评论对电影进行分类,所以。。我尝试了一些东西,但失败了

我有两张桌子

1-电影

id -- name
 1     XX
 2     YY
2集

id -- name
 1     XX
 2     YY
mid->来自第一个表的电影id

eid->剧集id

id -- mid -- eid -- comments
 1     1      1       4
 2     1      2       2
 3     1      3       2
 4     2      1       1
 5     2      2       1
我试过了

$q = mysql_query("SELECT SUM(comments) AS sum_comments, COUNT(mid) AS count_mid FROM episodes ORDER BY sum_comments DESC");
while($arr = mysql_fetch_array($q))
{
    echo $arr['count_mid']." - ".$arr['sum_comments']."<br/>";
}

Output: 5 - 10

Excepted: 1 - 8
          2 - 2
$q=mysql\u query(“选择SUM(comments)作为SUM\u comments,从按SUM\u comments DESC排序的剧集中选择COUNT(mid)作为COUNT\u mid”);
而($arr=mysql\u fetch\u数组($q))
{
echo$arr['count_mid'].“-”$arr['sum_comments'.“
”; } 产出:5-10 例外情况:1-8 2 - 2

非常感谢

评论存储在哪里?尝试-选择SUM(评论)作为SUM_评论,按中间顺序按SUM_评论从剧集组中选择midDESC@Aknosis谢谢,它很有效-b评论存储在哪里?尝试-选择SUM(评论)作为SUM_评论,按中间顺序按SUM_评论从剧集组中选择midDESC@Aknosis谢谢,它很有效-BDAH类似的答案在30秒前发布了…:)Ahh类似的答案在30秒前发布了…:)因为我不能给Aknosis提供一个接受的答案。。我会接受你的回答。谢谢因为我不能给Aknosis一个接受的答案。。我会接受你的回答。谢谢
select mid,sum(comments) as TotalCommentCount from episodes 
group by mid   order by  mid