由于某些原因,以下select语句不在mariadb 10中执行,但在mariadb 5.5中执行良好。在5.5中,它从这两个时间范围内的数据库中选择值。无法使用相同的数据库选择任何10。问题是什么?任何人? 谢谢。
$_SESSION['post-data'] = $_POST;
$t1 = $_SESSION['post-data']['t1'];
$t2 = $_SESSION['post-data']['t2'];
$time1 = mysqli_real_escape_string($conn, $t1);
$time2 = mysqli_real_escape_string($conn, $t2);
$sql = "SELECT DISTINCT msisdn FROM customer WHERE DATE_FORMAT(time_paid,'%Y-%c-%e')
BETWEEN ADDDATE('$time1',INTERVAL 0 HOUR)
AND ADDDATE('$time2',INTERVAL '23:59' HOUR_MINUTE)";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "Number of Recipients: "; echo "$result->num_rows <br> <br>";
// output data of each row
while($row = $result->fetch_assoc()) {
$mobilenumber[] = $row['msisdn'];
}
} else {
echo "No Contacts to Display";
}
$mob_numbers = implode(", " , $mobilenumber);
echo "$mob_numbers";
$_SESSION['numbers'] = $mob_numbers;
答案 0 :(得分:0)
假设time_paid为DATE_FORMAT
或DATE
或DATETIME
,请勿使用TIMESTAMP
。这将允许您使用索引。然后添加此复合INDEX(time_paid, msisdn)
;它会很有帮助并且“覆盖”。
然后将BETWEEN
更改为:
SELECT DISTINCT msisdn
FROM customer
WHERE time_paid >= $time1
AND time_paid < $time2 + INTERVAL 1 DAY