Merge 2 or more rows into 1 [message #668923] |
Fri, 23 March 2018 10:12 |
|
laredoeneko
Messages: 21 Registered: November 2017
|
Junior Member |
|
|
Hello,
i donot know if this is possible, i have a table with information like this:
element1 DOWN@14.29
element1 UP@85.71
element2 DOWN@50
element2 UP@50
is it possible get a query to get the output like this, group rows for the first column:
element1 DOWN@14.29 UP@85.71
element2 DOWN@50 UP@50
thank you very much
Cesar
SET DEFINE OFF;
Insert into PORTALES.TEST123
(SP2, PERCENT)
Values
('element1', 'DOWN@14.29');
Insert into PORTALES.TEST123
(SP2, PERCENT)
Values
('element1
', 'UP@85.71');
Insert into PORTALES.TEST123
(SP2, PERCENT)
Values
('element2', 'DOWN@50');
Insert into PORTALES.TEST123
(SP2, PERCENT)
Values
('element2', 'UP@50
');
COMMIT;
|
|
|
|
|
|
|
|
Re: Merge 2 or more rows into 1 [message #668931 is a reply to message #668930] |
Sat, 24 March 2018 01:11 |
|
Michel Cadot
Messages: 68694 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
... as the specification...
Please note you have to also give the column headers in your result chart.
You say the query is perfect but compare the result:
Yours:
element1 DOWN@14.29 UP@85.71
element2 DOWN@50 UP@50
The query:
SQL> SELECT Sp2, LISTAGG (Percent, ' ') WITHIN GROUP (ORDER BY Percent) AS Listing
2 FROM Test123
3 GROUP BY SP2
4 ORDER BY SP2;
SP2 LISTING
-------- --------------------
element1 DOWN@14.29 UP@85.71
element2 DOWN@50 UP@50
Not exactly the same one isn't it?
So query does not "work perfect" or what you posted is not correct.
[Updated on: Sat, 24 March 2018 01:20] Report message to a moderator
|
|
|
Re: Merge 2 or more rows into 1 [message #668932 is a reply to message #668923] |
Sat, 24 March 2018 02:35 |
John Watson
Messages: 8951 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Another solution,orclx>
orclx> select sp2,max(percent),min(percent) from test123 group by sp2;
SP2 MAX(PERCEN MIN(PERCEN
---------- ---------- ----------
element2 UP@50 DOWN@50
element1 UP@85.71 DOWN@14.29
orclx>
|
|
|