我正在尝试构建一个查询db和求和的短代码。以下是我目前掌握的情况:
function my_plugin_name_count_people() {
global $wpdb;
return $wpdb->query ("SELECT COALESCE(SUM(`column_one`), column_two ,0) FROM `table_name` WHERE `booking_date` = CURDATE() -10");
}
add_shortcode(\'countpeople\', \'my_plugin_name_count_people\');
这将返回“1”作为值,但如果我在myphpadmin中运行该语句,它将显示NULL。这是准确的,因为那天没有结果。有人知道为什么在SUM()计数上显示“1”吗?