Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

satheeshkumarj's avatar

Show syntax error in GROUP_CONCAT

Show syntax error in GROUP_CONCAT . I am using PostgreSQL this is my query

$query = DB::table('campaigns_history', 'camp_hist')
                    ->join('campaigns', 'campaigns.id', '=', 'campaigns_history.campaign_id')
                    ->join('companies', 'companies.id', '=', 'campaigns.company_id')
                    ->join('users', 'users.id', '=', 'campaigns_history.user_id')
                    ->join('templates', 'templates.id', '=', 'campaigns_history.template_id')
                    ->join('countries', 'countries.countries_iso_code', '=', 'users.country')
                    ->select('templates.template_name', 'companies.name as company_name', 'campaigns_history.id as historyId','campaigns_history.is_accept',
                        'campaigns_history.campaign_id',
                        'campaigns_history.updated_at',
                        'campaigns_history.sent_total_count',
                        DB::raw('SUM(if(campaigns_history.is_sent = 1, 1, 0)) total_sent_count'),
                        DB::raw('SUM(if(campaigns_history.status_button_id > 0, 1, 0)) total_accept_count'),
                        DB::raw('SUM(if(campaigns_history.is_accept = 0, 1, 0)) total_undecided_count'),
                        DB::raw('SUM(if(campaigns_history.is_accept = 1, 1, 0)) total_confirm_count'),
                        DB::raw('SUM(if(campaigns_history.is_accept = 2, 1, 0)) total_reject_count'),
                        DB::raw('GROUP_CONCAT(case when campaigns_history.is_sent = 1 then campaigns_history.user_id else " " end SEPARATOR ",") as sent_user_ids'),
                        DB::raw('GROUP_CONCAT(case when campaigns_history.status_button_id > 0 then campaigns_history.user_id else " " end SEPARATOR ",") as respond_user_ids'),
                        DB::raw('GROUP_CONCAT(case when campaigns_history.is_sent = 1 then campaigns_history.user_id else " " end SEPARATOR ",") as sent_user_ids'),
                        DB::raw('GROUP_CONCAT(case when campaigns_history.is_sent = 1 then campaigns_history.user_id else " " end SEPARATOR ",") as sent_user_ids'),
                        DB::raw('GROUP_CONCAT(case when campaigns_history.is_sent = 1 then campaigns_history.user_id else " " end SEPARATOR ",") as sent_user_ids'))
                    ->where('campaigns_history.campaign_id', '=', $campaignId);
0 likes
1 reply

Please or to participate in this conversation.