1 回答

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
您可以使用它
SELECT
packageId
FROM
(SELECT packageId, COUNT(*) AS totalSales FROM ph_paypal_payments
GROUP BY packageId) t1
ORDER BY totalSales DESC
LIMIT 1;
Ir 為您提供一個(gè)總銷售額最高的包 ID。即使還有更多,它仍然只得到其中之一。
這是基于行數(shù),而不是銷售數(shù)量。
$sql = "SELECT packageId FROM (SELECT packageId, COUNT(*) AS totalSales FROM ph_paypal_payments GROUP BY packageId) t1 ORDER BY totalSales DESC LIMIT 1;";
$stmt = mysqli_stmt_init($connection);
if (!mysqli_stmt_prepare($stmt, $sql)) die ("Prepare failed: " . mysqli_stmt_error($stmt));
mysqli_stmt_bind_param($stmt, "i", $packageId);
mysqli_stmt_execute($stmt);
return mysqli_fetch_assoc(mysqli_stmt_get_result($stmt))['packageId'];
- 1 回答
- 0 關(guān)注
- 99 瀏覽
添加回答
舉報(bào)