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 |
CodePudding user response:
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;