我正在尝试运行此查询
$revs = DB::table('reviews')->where('website_id', $website_id)
->selectRaw('
COUNT(id) AS total_count,
COUNT(id) AS third_party_reviews_count WHERE review_source_id!=1,
COUNT(id) AS normal_reviews_count WHERE review_source_id=1,
COUNT(id) AS total_1_star WHERE stars = 1,
COUNT(id) AS total_2_star WHERE stars = 2,
COUNT(id) AS total_3_star WHERE stars = 3,
COUNT(id) AS total_4_star WHERE stars = 4,
COUNT(id) AS total_5_star WHERE stars = 5')->get();
但上面说
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COUNT(id) AS normal_reviews_count WHERE `review_source_id`=1,COUNT(id) AS
我尝试使用在线SQL语法检查器,但没有一个给我解决这个问题的方法。
1条答案
按热度按时间eqqqjvef1#
您可以编写整个sql查询,然后像这样运行它: