Home How to combine two rows under specific condition
Reply: 0

How to combine two rows under specific condition

user796
1#
user796 Published in April 26, 2018, 1:42 pm

I have following table:

CREATE table table1 (id int , cd date, ct TIME, co text)

INSERT INTO table1 
VALUES (0, '1/1/2018', '12:00:00', 'B'), 
        (1, '1/1/2018', '12:30:00', 'BC'), 
        (2, '1/12/2018', '12:00:00', 'B'), 
        (3, '1/22/2018', '12:00:00', 'BC')

I need to combine "co" column when values of "cd" and "ct" columns are the same for 'B' AND 'BC' or only values of "ct" are different and display values of record 'B' for 'B-BC'. for the above table1 records I need following result:

"id"    "cd"    "ct"    "co"
"0" "1/1/2018"  "12:00:00 PM"   "B-BC"
"2" "1/12/2018" "12:00:00 PM"   "B"
"3" "1/22/2018" "12:00:00 PM"   "BC"

What is the most effective way to do that in postgresql 8.4?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.520514 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO