Ask Your Question
0

How can I combine three records into one in postgresql and include new columns with the combined values?

asked 2023-02-07 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-01-09 05:00:00 +0000

woof gravatar image

You can use the GROUP BY clause along with aggregate functions like SUM, AVG, etc. to combine multiple records into one. For example, if you have three records with columns col1, col2, and col3, you can group them by a common column and sum their values using the following query:

SELECT common_col, SUM(col1) AS total_col1, SUM(col2) AS total_col2, SUM(col3) AS total_col3
FROM your_table
GROUP BY common_col

This query will create a new column for each original column with the combined values, using the SUM function. You can also use other aggregate functions depending on your requirements.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-07 11:00:00 +0000

Seen: 10 times

Last updated: Jan 09 '22