0

I'm trying to merge the values of two rows based on the value of another row in a different column. Below is my based table

Customer ID Property ID Bookings per customer Cancellations per customer
A 1 0 1
B 2 10 1
C 3 100 1
C 4 100 1
D 5 20 1

Here is the SQL query I used

select customer_id, property_id, bookings_per_customer, cancellations_per_customer
from table

And this is what I want to see. Any ideas the query to get this would be? We use presto SQL

Thanks!

Customer ID Property ID Bookings per customer Cancellations per customer
A 1 0 1
B 2 10 1
C 3 , 4 100 1
D 5 20 1
jarlh
  • 42,561
  • 8
  • 45
  • 63
bobbytici
  • 45
  • 4
  • 1
    https://stackoverflow.com/questions/44142356/presto-equivalent-of-mysql-group-concat can perhaps help. – jarlh Jan 27 '23 at 10:21

1 Answers1

1

We can try:

SELECT
    customer_id,
    ARRAY_JOIN(ARRAY_AGG(property_id), ',') AS properties,
    bookings_per_customer,
    cancellations_per_customer
FROM yourTable
GROUP BY
    customer_id,
    bookings_per_customer,
    cancellations_per_customer;
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360