gpt4 book ai didi

php - ID 多的总值(value)总和

转载 作者:行者123 更新时间:2023-11-29 08:30:06 24 4
gpt4 key购买 nike

我尝试获取内容 ID,这是查询...

$getIDs = mysql_query("SELECT content_id FROM playlist_content WHERE playlist_id=".$rrow['playlist_id']."") or die(mysql_error());
while($row = mysql_fetch_array($getIDs)) {
$array[] = $row;
}

这是结果

Array
(
[0] => Array
(
[0] => 33
[content_id] => 33
)

[1] => Array
(
[0] => 13
[content_id] => 13
)

[2] => Array
(
[0] => 8
[content_id] => 8
)
)

现在必须从具有此 ID 的第二个表获取值注意:ID = content_id

$result =  mysql_query("SELECT SUM( length ) as total FROM content WHERE ID ...

并回显所有行的总和['length',这个ID在哪里需要返回结果,例如 102256 等...

或者有没有更好的方法来获取总和?

最佳答案

实际上,您可以通过连接两个表在单个查询中完成此操作,

SELECT  a.content_id, SUM(b.length) TotalSum
FROM playlist_content a
INNER JOIN content b
ON a.content_id = b.ID
WHERE a.playlist_id = IDHERE
GROUP BY a.content_id

查询结果将为您提供每个 content_idlength 总和。

要进一步了解有关联接的更多知识,请访问以下链接:

关于php - ID 多的总值(value)总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16868873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com