Client id Insurance
------------ ---------------
123 AA
123 EE
123 U
125 AA
126 CU
124 UE
125 UE
I want my out put to be:
Client id Number of rows Insurance
------------ ----------------------- --------------
123 3 AA,EE,U
125 2 AA,UE
126 1 CU
124 1 UE
PHPPostgreSQL
Last Comment
Jazzy 1012
8/22/2022 - Mon
Jazzy 1012
ASKER
I also tried this
SELECT client_id, concat(count(*), ' rows') AS rows, array_agg(insurance) AS insurance FROM vouchers WHERE parsing_date=CURRENT_DATEGROUP BY client_id;
Warning: pg_query(): Query failed: ERROR: function concat(bigint, unknown) does not exist LINE 1: SELECT client_id, concat(count(*),'rows') AS rows, array_agg... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. in index.php on line 8
array_agg() isn't Postgres
I can't help on PHP functions
do you want a Postres solution or a PHP solution?
PortletPaul
did you try it like this?
$query= "
SELECT v.Client_id, string_agg(v.Insurance,',' order by v.Insurance)
from vouchers v
WHERE v.parsing_date=CURRENT_DATE
group by v.Client_id
";
$result = pg_query($conn,$query);
Open in new window
But I got this error:
Open in new window
(line 8 Is that line(query))