我试图计算一个数字连续出现的次数(为了计算每人的销售数量)我在我的数据库books
,shelf
中有这些表,这是我的代码
$UBooks = $dbhandle->query("SELECT * FROM books
INNER JOIN shelf ON books.id = shelf.bookid WHERE books.author_id = '$id';
");
if ($UBooks->num_rows > 0)
{
while($row = $UBooks->fetch_assoc())
{
$ruid = $row["bid"];
$title = $row["title"];
$description = $row["description"];
$bookurl = "../../".$row["bookurl"];
$publish = $row["publish"];
$price = $row["price"];
$Fullname = $row["bookid"];
if($publish == 1)
{
$publish = '<input type="checkbox" checked bid="'.$ruid.'" title="Click to Un-Publish Book" onchange="activateBook(this);" />';
}
else if ($publish == 0)
{
$publish = '<input type="checkbox" bid="'.$ruid.'" title="Click to Publish Book" onchange="activateBook(this);" />';
}
else if ($publish == 3)
{
$publish = '<input type="checkbox" bid="'.$ruid.'" title="Click to Publish Book" onchange="activateBook(this);" /> <label>For Review</label>';
}
$BooksTab .= '<tr>
<td>'.$title.'</td> <td>'.$description.'</td> <td>'.$price.'</td>
<td>'.$Fullname.'</td>
</tr>';
}
}
?>
所以我正在寻找一种方法来计算bookid
中货架表中出现的一个数字作为行,例如,如果3在货架表中出现3次而不是计算它并将其显示为数量销售= 7
答案 0 :(得分:0)
你可能不需要加入
SELECT bookid, count(*)
FROM shelf
GROUP BY bookid