Pivot of the Oracle
I want to know if there is a better way to run this query.The current table layout
group division class stage endage rate
Go 001 01 0 19 .4
Go 001 01 20 24 .5
G0 001 01 25 29 .6
G0 001 01 30 34 .2
Required output
group division class a1 ae1 rt1 a2 ae2 rate2 a3 ae3 rt3 a4 ae4 rt4
Go 001 01 0 19 .4 20 24 .5 25 29 .6 30 34 .2
I'm trying to do this using a function passing rownum, class, division, group as parameters. Performance is not bad.I was wondering if there was any other way to do it too.
I use Oracle 10.2
Thanks in advance
Hello
Bob wrote:
... This is the example you want me to try? ...
Yes, something like that. As I've mentioned before, you'll want to MIN or MAX instead of COUNT.
If so could you please link to my table. I guess I won't be able to do this way. I have to use PivotChart. because I will not know the rates to hardcode.
Rates matter? Judging by the function you have posted, it resembled "ROW_NUMBER"... ORDER BY low_age"was the crucial thing, which determines whether a given line would end up in the game of 1st, 2nd, 3rd or 4th of arms, and you do not know the values that ROW_NUMBER will return: 1, 2, 3 and 4.
I think you want something like this:
WITH got_c_num AS
(
SELECT group_number
, division
, class_col -- CLASS is not a good column name
, stage
, endage
, rate
, ROW_NUMBER () OVER ( PARTITION BY group_col
, division
, class_col
ORDER BY low_age
) AS c_num
FROM test
-- WHERE ... -- If you need any filtering, put it here
)
SELECT group_number, division, class_col
, MIN (CASE WHEN c_num = 1 THEN stage END) AS a1
, MIN (CASE WHEN c_num = 1 THEN endage END) AS ae1
, MIN (CASE WHEN c_num = 1 THEN rate END) AS rt1
...
, MIN (CASE WHEN c_num = 4 THEN stage END) AS a4
, MIN (CASE WHEN c_num = 4 THEN endage END) AS ae4
, MIN (CASE WHEN c_num = 4 THEN rate END) AS rt4
, endage
, rate
FROM got_c_num
GROUP BY group_number, division, class_col
ORDER BY group_number, division, class_col
;
I make several assumptions about your table and your data.
If post you some examples of data (CREATE TABLE and INSERT statements) and outcomes from these data, I was able to test this.
Tags: Database
Similar Questions
-
11G Pivot query with Oracle EBS
Hi all
We try to use the request function pivot 11G with Oracle E-Business Suite data. We have a database 11G installed with our Oracle APEX. We do not seem to get the pivot function to work. In short, anyone would be able to see the glaring errors in our syntax. I am not sure that it is possible to provide data of test so...
We try to have with the period column headers names SEP-08 OCT-08 NOV-08, with rows of segment2 007751 and accounted_dr as DataSet.
When we run the sql code we get an error ORA-00904: "PERIOD_NAME": invalid identifier.
Any help or idea would be greatly appreciated.
Select * from)
Select segment2, accounted_dr, period_name
gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = "007751")
Pivot
(
Sum (accounted_dr)
for period_name ("SEP-08', ' 08 OCT ', ' NOV-08'")
)
Segment2 group, period_namelilhelp wrote:
Hi all
We try to use the request function pivot 11G with Oracle E-Business Suite data. We have a database 11G installed with our Oracle APEX. We do not seem to get the pivot function to work. In short, anyone would be able to see the glaring errors in our syntax. I am not sure that it is possible to provide test dataWhy not?
>We try to have with the period column headers names SEP-08 OCT-08 NOV-08, with rows of segment2 007751 and accounted_dr as DataSet.
When we run the sql code we get an error ORA-00904: "PERIOD_NAME": invalid identifier.Any help or idea would be greatly appreciated.
Select * from)
Select segment2, accounted_dr, period_name
gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = "007751")
Pivot
(
Sum (accounted_dr)
for period_name ("SEP-08', ' 08 OCT ', ' NOV-08'")
)
Segment2 group, period_nameDo not use GROUP BY. When you use PIVOT, the group is involved with what is in the PIVOT clause and which is not.
Try this:select * from ( select segment2 , accounted_dr , period_name from gl_je_lines a , gl_code_combinations b where b.code_combination_id = a.code_combination_id and segment2 = '007751' ) pivot ( sum (accounted_dr) for period_name in ('SEP-08','OCT-08','NOV-08') ) ;
which is just your query validated without the GROUP BY clause.
-
I see that Javascript is enabled. Is javascript and java, the same thing?
To avoid confusion:
Note that you need the Web-IcedTea Plugin installed and it is a different implementation of Java as the Oracle's Java plugin (formerly Sun), while the Oracle does not detect this plugin.
-
How can I change the oracle schema in SSMA?
We tested migration in SSMA for Oracle to SQL Server, and we are now ready to migrate from the production data. However, the SSMA tool doesn't let me change the Oracle schema. I can change the data source, but it will never refresh show new patterns in Oracle.
Hello
Please go to the Microsoft Community Forums.This problem would be better suited to the TechNet community.
Please visit the link below to find a community that will provide the support you want.Thank you. -
I want to know the oracle commands in the syntax descriptions
Hello Sir,
I want to know the commands that is used in oracle 10 g and guide please to import excel tables to oracle
Hello
Your question is related to the Oracle and would be better suited to the Oracle forum:
-
SSRS for lack of outer join with the Oracle data source
It seems to be a problem with the Oracle driver used in the Reporting SERVICES query designer.
When you use an Oracle data source, if I create an outer join in the graphic designer, it automatically inserts '{OJ' before the join and '} ' after her. This is an incorrect syntax for Oracle and refuses to start. The curly braces and the JO editable in designer text, but if I go back to the graphic designer and immediately to reintegrate them.
Only, this has started to happen a year or two ago - before that it worked, but with the old (+) syntax.
Can it not be healed? It makes things very difficult.
-Geoff
Hi Geoff,
Thanks for posting in the Microsoft Community.
However, the question you posted would be better suited in the Forums of the Oracle Support; We recommend that you post your query in Oracle Support Forums to get help:
If you have any other questions or you need Windows guru, do not hesitate to post your questions and we will be happy to help you.
-
Database alert is not triggered when the Oracle database monitor by mistake.
Hello
Database alert is not triggered when the monitor of the Oracle database by mistake. If we test the alert manually alert works correctly. Could someone let me know the solution for this.
This isn't a question of PC or operating system. You should post your questions in the forums of Oracle database.
-
ASM and SCAN listener running of the Oracle user not user network
Hi all
Greetings for the day!
In one of my new customer environment, I see that ASM and SCAN are running oracle user not user network, although the ORACLE_HOME is on the grid software. I read somewhere that we should run ASM and SCAN from grid not Oracle. Please let me know if I'm right and if there are consequences of the performer of the Oracle user.
OS: Red Hat Enterprise Linux Server 6.5 (Santiago) 64-bit release
Oracle RDBMS: 11204
Oracle GI: 11204
CAR Info: 2 node cluster.
Thank you very much.
AbbDBA
The important word is expected here. It is suggested that 11.2, that the separation of roles, a non-oracle account must be used for the GI. But this is not essential, and certainly not wrong to use Oracle db and IM account as long as you do not use ASM according to security features. So nothing to worry about. You're good.
Aman...
-
The getCurrent method on the oracle.adf.share.ADFContext class is not allowed
Hi all
I've migrated my old project i.e 12.1.3 to new version 12.2.1.
After the migration of the project where ever, we use ADFContext.getCurrent () .getSessionScope () .put ("dummy", 1);
put the variable in the session. We receive the exception as Houston-25150: the getCurrent method on the oracle.adf.share.ADFContext class is not allowed. In the earlier version, but its works very well.
What will be the question. Please can someone let me know.
Thank you
Amar
This error except for security, so try to use the expression adf.context.current.sessionScope.get ("dummy") (or attempt to use this as a groovy adf.context.sessionScope.dummy expression) attribute EO and trustMode = "true" for this attribute set.
For more details check this url
-
Skip and capture the Oracle SQL record dirty in a select statement
Hello
I have the Oracle Oracle 11.2.0.4 database when I run a select query.
Question:
10 columns have given Date format. When I try to execute this query into a FROG he says, a month not valid. Since the records are billion in nature, I am not able to know which line has this problem.
Is there a way I can capture the failed row and add it to other tables and continues with the select statement regardless of this error
OK, you have several TO_DATE functions fed a string that is built on the fly. At least part of the time, the chain that is built does not match the date format mask used.
For example:
TO_DATE (SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID), 0, 8). » -'|| SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. (LAST_SUBMITTED_ON_DTTM_WID), 9, 6), "YYYYMMDD-HH24MISS")
"SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' does not have a string where characters 5-6 are in the range 01-12. You'll have to do an analysis on this column. From its data and how that is managed by to_char. What ARE the data type of ' SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' and what is a typical value?
As others have said, this is simply an impossibility for a column of a table to actually have invalid month (or day, or year, or hour or minute or second). ONLY, you get this error during the conversion of a string to a date with the TO_DATE function.
-
How to get the column provided out of the Oracle Data Miner?
Hi all!
I use Oracle Data Miner provided with Oracle SQL Developer to predict the loss of customers. If I plan on the table column lets say X (as a target column) of table say T, so how can I get the corresponding values under my model?
Here is the simplified model for the reference.
Thanks in advance!
Hello
Simply connect a node that accepts data to the node to apply it.
For example, if you want to create a view or table table using the prediction of outputs generated by the node to apply it, and then add a Create Table node and connect the node to apply it.
For more information, try the Oracle by example tutorials for ODMr.
You must use the node apply Publisher to revise prediction outputs models to generate as well as the additional columns to include, for example columns id.
There are a set of predictor columns added by default that may be acceptable.
THX, mark
-
Hello world
I want to not know le Headline to understand the ORACLE performance tuning.
And thank you
Hello
You can quickly go through 2 days guide
Oracle Database 2 day + Performance Tuning Guide
https://docs.Oracle.com/database/121/TDPPT/tdppt_preface.htm#TDPPT336
Concerning
Hitgon
-
What is the name of the table that has the name of the custom in the Oracle database Section?
What is the name of the table that has the name of the custom in the Oracle database Section?
Thank you
Nefertari
The names of the custom Sections are stored in commonExtendedAttributeML, the extended attribute table.
-
You are not currently connected to the Oracle BI server
Hi I am facing problem while that connection in the page of answers... Here is the message I get... Please someone help, what could be the matter, thank you
You are not currently connected to the Oracle BI server. If you have already logged in, your login may have expired, or a communication or a server error occurred.
To reconnect, click here. If the problem persists, please contact the site administrator. »
Hi Ram,
My question was resolved, it happened because of OPMN services are low.
-
Do not have access to the oracle community ideas
Hello
Why don't I have access to the Oracle community ideas
Ideas have been disabled by the administrator due to issues around spamming. They hope it is resolved quickly so that the ideas can be relit.
Maybe you are looking for
-
No one knows how long a hp support assistant analysis should take mine has been sweeping for more than 2 hours and a half
-
Backlight HP become darker after you apply windows updates
Hi there I have a problem with my pavilion dv6200 This is the third time the same thing is happening to me. After I install some updates, display DIMM, and background light became darker. When I restart the computer and enter the BIOS, or if I am loo
-
HP PSC 1315 all-in-One use scanner without ink cartridges
Hello Is it possible to use HP PSC 1315 scanner without ink cartridges? A light ink control is brinking and it won't scan.
-
I HAVE NO SOUND ON MY COMPUTER WITH WINDOWS XP PRO
My computer crashed and has upgraded windows xp to XP pro and now I have no sound
-
Original title: program compatibility Application Applications App Apps game games Legacy Crash crashes Hang hangs I had Skype downloaded into my computer. a lat night work, but now it says incompatible