简体   繁体   中英

Merge two rows in a single one Postgresql

I have a database postgresql with a table representing the events performed by a user. Here an example:

|userid|phone_number|       email       |   event_type  |     created_on    |
|------|------------|-------------------|---------------|-------------------|
|123456| +xx12398756|                   |change-username|2020-11-09 19:20:58|
|123456|            |example@yopmail.com|change-username|2020-11-09 19:19:16|

I would like to extrcat all the users that have performed an event on che phone numeber and on the email like this:

|userid|phone_number|       email       |   event_type  |
|------|------------|-------------------|---------------|
|123456| +xx12398756|example@yopmail.com|change-username|

How can i do the query?

thank you

Do you want aggregation?

select userid, max(phone_number), max(email), event_type
from t
group by userid, event_type;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM