我想做一个tripple mysql查询。但我无法管理它:
//第一部作品
mysql_connect($host, $user,$passwd) or die("Fehler bei der Verbindung zum Server");
mysql_select_db($bdd) or die("Fehler bei der Verbindung zur Datenbank");
$abfrage = "SELECT * FROM plugins WHERE title IN ('$title')";
$ergebnis = mysql_query($abfrage);
$row = mysql_fetch_object($ergebnis);
$title = $row->title;
$link = $row->link;
$data = $row->data;
//这是执行工作的代码。
$abfrage2 = "SELECT COUNT(rate) FROM rate WHERE title IN ('$title')";
$countRatings = mysql_query($abfrage2);
$abfrage3 = "SELECT AVG(rate) FROM rate WHERE title IN ('$title')";
$avgRatings = ceil(mysql_query($abfrage3));
是否有可能连接此查询?
答案 0 :(得分:0)
您可以使用JOIN
,例如:
SELECT p.*, COUNT(r.rate) AS `count`, AVG(r.rate) AS `average`
FROM plugins p JOIN rate t ON p.title = r.title
WHERE p.title IN ('$title');
答案 1 :(得分:0)
是的,但您可能需要指定插件列。
select p.title, count(r.rate), avg(r.rate)
from plugins p
join rate r
on p.title = r.title
where p.title in ('$title')
group by p.title;