Hello everyone,
Not sure if you can help but I am stuck with this query.
I have a view that looks like below. I hope you can read this table.
ITEM_ID|STAGE |COUNT|TRIM_SIZE|BINDING
2083109|BUDGET |512 |8 X 10||
2083109|P.N. |464 |8 X 10|Perf Bnd|
2083109|R.T. |432 |8 X 10||
2083109|TRANS |544 |8 X 10||
The data shows different page count values for the same item at different stages. I want to show this info into one row by using the SUM and DECODE functions, like this:
SELECT nt1.inventory_item_id,
sum(DECODE (nt1.stage, 'BUDGET', nt1.COUNT, 0)) b_count,
sum(DECODE (nt1.stage, 'TRANS', nt1.COUNT, 0)) t_count,
sum(DECODE (nt1.stage, 'P.N.', nt1.COUNT, 0)) pn_count,
sum(DECODE (nt1.stage, 'R.T.', nt1.COUNT, 0)) rt_count,
nt1.trim_size
FROM scorecard_inner_v nt1
GROUP BY nt1.inventory_item_id,
nt1.trim_size
I can get it in one line if I select only up to the field TRIM_SIZE. But I also want to include the last field BINDING. If I use just the decode function then I end with up with two rows and not one. If use the SUM and DECODE function together like with the other fields, then it doesnt work. Any suggestions.
PS: by the way, I want the value 'Perf Bnd' to appear for the BINDING field in that one row that I want outputted.
Thanks,
Mirgoak
Not sure if you can help but I am stuck with this query.
I have a view that looks like below. I hope you can read this table.
ITEM_ID|STAGE |COUNT|TRIM_SIZE|BINDING
2083109|BUDGET |512 |8 X 10||
2083109|P.N. |464 |8 X 10|Perf Bnd|
2083109|R.T. |432 |8 X 10||
2083109|TRANS |544 |8 X 10||
The data shows different page count values for the same item at different stages. I want to show this info into one row by using the SUM and DECODE functions, like this:
SELECT nt1.inventory_item_id,
sum(DECODE (nt1.stage, 'BUDGET', nt1.COUNT, 0)) b_count,
sum(DECODE (nt1.stage, 'TRANS', nt1.COUNT, 0)) t_count,
sum(DECODE (nt1.stage, 'P.N.', nt1.COUNT, 0)) pn_count,
sum(DECODE (nt1.stage, 'R.T.', nt1.COUNT, 0)) rt_count,
nt1.trim_size
FROM scorecard_inner_v nt1
GROUP BY nt1.inventory_item_id,
nt1.trim_size
I can get it in one line if I select only up to the field TRIM_SIZE. But I also want to include the last field BINDING. If I use just the decode function then I end with up with two rows and not one. If use the SUM and DECODE function together like with the other fields, then it doesnt work. Any suggestions.
PS: by the way, I want the value 'Perf Bnd' to appear for the BINDING field in that one row that I want outputted.
Thanks,
Mirgoak