-1

I use this code. but, it is giving me the error string_agg does not exist.

What to do?

select customer_id, budget, count(*) as no_of_product , string_agg(p.product_id) as list_of_product 
FROM customer_budget c
left join 
(SELECT * , sum(cost) over (order by cost) as r_cost FROM product) p
on c.budget>=p.r_cost 
group by customer_id, budget
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Sk337
  • 1
  • 2

1 Answers1

1

The error is correct: string_agg() does not exist in MySQL. That isn't standard SQL, and it isn't part of MySQL. That appears to be part of T-SQL (SQL Server).

I think the closest MySQL analog is group_concat(). In this case, I think you can just drop it in:

select customer_id
     , budget
     , count(*) as no_of_product
     , group_concat(p.product_id) as list_of_product -- here
from customer_budget c
left join 
(select *
      , sum(cost) over (order by cost) as r_cost
 from product
) p
on c.budget >= p.r_cost 
group by customer_id
       , budget
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257