我正在尝试计算SQL中值的出现次数
id | my_id | field_number | field_id | value
------------------------------------------------------------
1 | 101 | 78 | 88 | apple
2 | 287 | 76 | 55 | orange
3 | 893 | 45 | 33 | orange
4 | 922 | 23 | 33 | grape
5 | 198 | 09 | 88 | raisin
6 | 082 | 55 | 88 | apple
如果我使用以下内容,那么它正确地告诉我有3个field_id的值为88 .....
$count = $wpdb->get_results("SELECT COUNT(*) as count FROM wp_db1 WHERE field_id=88");
但如果我尝试这样做:
$count = $wpdb->get_results("SELECT COUNT(*) as count FROM wp_db1 WHERE value=apple");
然后它不起作用。有人可以帮忙吗?
答案 0 :(得分:3)
您错过了apple
周围的引号:
$count = $wpdb->get_results('SELECT COUNT(*) as count FROM wp_db1 WHERE value="apple"');