好時光!告訴我如何優化這個查詢,如果可能的話,把它合併成一個!mysql多組通過
$query = "SELECT external_source_id FROM smf_tds_unique_statistic WHERE ".$dateRange." GROUP BY external_source_id ORDER BY external_source_id ASC;";
$query .= "SELECT sources_id FROM smf_tds_unique_statistic WHERE ".$dateRange." GROUP BY sources_id ORDER BY sources_id ASC;";
$query .= "SELECT ip_country FROM smf_tds_unique_statistic WHERE ".$dateRange." GROUP BY ip_country ORDER BY ip_country ASC;";
$query .= "SELECT cidr FROM smf_tds_unique_statistic WHERE ".$dateRange." GROUP BY cidr ORDER BY cidr ASC;";
if (mysqli_multi_query($db, $query)) {
do {
if ($result = mysqli_store_result($db)) {
while ($row = mysqli_fetch_row($result)) {
$val = $row[0];
if ($val != '') {
$options .= '<li class="select_input_option_item" value="'.$val.'">'.$val.'</li>';
}
}
array_push($optionsArr, $options);
$options = '';
mysqli_free_result($result);
}
if (!mysqli_more_results($db)) break;
} while (mysqli_next_result($db));} mysqli_close($db);
當詢問SQL查詢問題時,請始終在查詢中引用的表中包含「SHOW CREATE TABLE」的輸出,因此我們不必猜測列和您目前可能擁有的索引。另外請讓我們知道你的'$ dateRange'變量包含什麼。否則,這對我們來說是個謎。 –