Home > database >  Multi-line merger
Multi-line merger

Time:09-19

Suppose you have table t

Col1 col2 col3
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
T a null
A null s
B t null
B null s

Looking forward to the result set of


Col1 col2 col3
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
A t s
B t s

Could you tell me how to write SQL statements urgent urgent

CodePudding user response:

His top!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

Select col1, Max (col2), Max (col3) from tab1 group by col1.

CodePudding user response:

 with TMP as 
(select the 'a' as col1, 't' as col2, null as col3 from dual
Union all
Select the 'a' as col1, null as col2, 's' as col3 from dual
Union all
Select 'b' as col1, 't' as col2, null as col3 from dual
Union all
Select 'b' as col1, null as col2, 's' as col3 from dual
)
Select col1,
Max (col2) col2,
Max (col3) col3
The from TMP
Group by col1
  • Related