我有一个数据库,我试图用一个LIMIT
来总结一个特定点的列,然后返回总和值,但它不起作用。这就是我所拥有的:
<?php
$servername = "localhost";
$username = "xxxxx";
$password = "xxxxxx";
$dbname = "xxxxxx";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die ("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT sum(donation_count) FROM (SELECT donation_count FROM users LIMIT 9) AS value_sum";
$result = $conn->query ($sql);
if ($result-> num_rows> 0) {
while ($row = $result->fetch_assoc()) {
echo '<div>'".$row['value_sum']."'</div>';
}
}
?>
答案 0 :(得分:1)
SELECT sum(donation_count) as value_sum FROM (SELECT donation_count FROM users LIMIT 9) AS temp