Home » SQL & PL/SQL » SQL & PL/SQL » Select where show information from two row in one row
Select where show information from two row in one row [message #272931] |
Mon, 08 October 2007 04:22  |
antti
Messages: 2 Registered: October 2007 Location: finland
|
Junior Member |
|
|
Hi
This is my first post here so please be kind!
My problem is that I need to show the result in one row but my query returns two
the result looks like this
|name |description |location |supplier |code |amount |
xxx something p1 x123 EUR 2
xxx something p1 x123 JAK 6 X 50
yyy something p3 x123 EUR 2
eee something p6 x123 EUR 2
as shown here there can be one or two rows per name and now I want this result looks like this
|name |description |location |supplier |code |amount |code2 |amount2 |
xxx something p1 x123 EUR 2 JAK 6 X 50
yyy something p3 x123 EUR 2
eee something p6 x123 EUR 2
so if there is two returns for the same name they would show in same row else it be empty string
|
|
|
|
|
|
|
Re: Select where show information from two row in one row [message #273378 is a reply to message #272939] |
Wed, 10 October 2007 03:46  |
antti
Messages: 2 Registered: October 2007 Location: finland
|
Junior Member |
|
|
Thank you all for your help this is my solution for the problem.
select a.*, case
when a.box1_code like 'LTK%' then '1'
when a.box1_code like 'PAHVI' then '1'
when a.box1_code like 'JAKO2' then '1'
when a.box1_code like 'PEU%' then '2'
when a.box1_code like 'EU%' then '2'
when a.box1_code like 'FI%' then '2'
when a.box1_code like 'JAKO1' then '2'
end box
from(
select part, description, leadtime, location,
lot_size, supplier_id, supplier,
max(decode(pivot,1,loadcode,'')) box1_code,
max(decode(pivot,1,amount,'')) box1_amount,
max(decode(pivot,2,loadcode,'')) box2_code,
max(decode(pivot,2,amount,'')) box2_amount
from(
select a.part_no part, a.Description description,
a.LEADTIME leadtime, b.LOCATION_NO location,
c.LOT_SIZE lot_size, d.VENDOR_NO supplier_id,
using_api.GET_Name(d.VENDOR_NO) supplier,
min(e.code) loadcode, e.value amount,
rank() over(partition by a.part_no order by e.code) pivot
from table1 a, table2 b,
table3 c, table4 d,
table5 e
where a.part_no = b.part_no and a.part_no = c.part_no
and a.part_no = d.part_no and a.part_no = e.part_no
and a.part_no in ('part1','part2')
group by a.part_no, a.Description, a.LEADTIME, b.LOCATION_NO,
c.LOT_SIZE, d.VENDOR_NO, e.code, e.value order by a.part_no
)
) a order by box, location
this is little bit modified but this is what I did. If some one can show easier way I'm happy to heard it.
And Thanks to all!!
|
|
|
Goto Forum:
Current Time: Tue Feb 18 00:36:29 CST 2025
|