Pivot problem
Hi master,
I have a requirement to display the output as like that... I give fake values of table and column. If I get the desired result, that I can work on my data in the table. I want to use pivot does not decode function. Please notify.
create table fruits (name varchar2 (10), type varchar2 (10), NTC number (3));
Insert into SCOTT. FRUIT
(NAME, TYPE, CNT)
Values
('Apple', 'Add', 20);
Insert into SCOTT. FRUIT
(NAME, TYPE, CNT)
Values
('Apple', 'change', 21);
Insert into SCOTT. FRUIT
(NAME, TYPE, CNT)
Values
('Apple', 'delete', 22);
Insert into SCOTT. FRUIT
(NAME, TYPE, CNT)
Values
("grapes", "add", 31);
Insert into SCOTT. FRUIT
(NAME, TYPE, CNT)
Values
("grapes", "Edit", 32);
Insert into SCOTT. FRUIT
(NAME, TYPE, CNT)
Values
("grapes", "delete", 33);
COMMIT;
out of desire.
name add edit delete
Apple 21 22 23
31 32 33 grape
Please advise... !
(NAME, TYPE, CNT) fruits as long as)
Select 'Apple', 'Add', 20 double Union all
Select 'Apple', 'change', 21 double Union all
Select 'Apple', 'delete', 22-dual union all
Select 'grape', 'Add', 31 to double union all
Select "grape", "edit", 32 double Union all
Select 'grapes', 'delete', 33 to double
)
Select *.
fruit
pivot)
Sum (NTC)
to TYPE in ('Add' as 'ADD', 'Edit' under 'EDIT', 'delete' that 'DELETE')
)
by NAME
NAME | ADD | EDIT | DELETE |
"Apple." | 20 | 21 | 22 |
"grapes". | 31 | 32 | 33 |
Tags: Database
Similar Questions
-
Hi all.
I use of Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 and the following query:
SELECT *.
Of
(SELECT code_combination_id, period_name, nvl (sum (begin_balance_dr + period_net_dr - begin_balance_cr - period_net_cr), 0))
OF gl_balances
) PIVOT (nvl (sum (gb.begin_balance_dr + gb.period_net_dr - gb.begin_balance_cr - gb.period_net_cr), 0))
I always get the error "Missing key word".
Can someone please give me a hand on this?
Octavio
Hello
because your statement is not complete, missing the PIVOT 'FOR' clause.
that is to say:
Select * from)
Select times_purchased, state_code
customers t
)
Pivot
(
Count (state_code)
for state_code ("NY", "CT", "NJ", "FL", "MO")
)
order of times_purchased
Please check: Re: 4. How can I convert rows to columns?
For a few examples.
Kind regards.
Alberto
-
< h3 > basically what I need is to generate a report that convert values to single column into multiple columns and aggregate data.
All the RptDate that are < current year are lump together. Status = 0 are the filter out.
My database is Oracle 9i release 9.2.0.1.0This is the info table ID RptDate Status JMN 01-Mar-08 1 JMN 01-Mar-08 1 JMN 05-Jun-09 1 JMN 14-Dec-10 1 JMN 23-Jan-11 0 JMN 26-Feb-11 1 BEN 01-Mei-08 1 BEN 01-Jul-08 1 BEN 22-Nov-09 1 BEN 23-Nov-09 1 BEN 14-Dec-10 1 BEN 23-Jan-11 1 BEN 29-Jan-11 1 BEN 26-Feb-11 1 BEN 21-Mar-11 1 KEN 07-Mei-07 1 KEN 04-Jan-08 1 KEN 28-Feb-08 1 KEN 22-Nov-09 1 KEN 23-Nov-09 1 KEN 14-Dec-10 1 KEN 23-Jan-11 1 KEN 29-Jan-11 1 KEN 26-Feb-11 1 KEN 21-Mar-11 0 KEN 01-Apr-11 1 Expected output ID PreviousYear Jan Feb Mar Apr Mei Jun Jul Aug Sep Oct Nov Dec Total JMN 4 0 1 0 0 0 0 0 0 0 0 0 0 5 BEN 5 2 1 1 0 0 0 0 0 0 0 0 0 9 KEN 6 2 1 0 1 0 0 0 0 0 0 0 0 10
This solution can give you the right EXIT, take a look...
SELECT ID,
Sum (case when RptDate<= trunc(sysdate,'yyyy')-1="" then="" 1="" else="" 0="" end)="" previousyear="">=>
sum (case when trunc (RptDate, 'month') = trunc(sysdate,'yyyy') then 1 else 0 end) jan.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 1) then 1 else 0 end) Feb.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 2) then 1 else 0 end) mar.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 3) then 1 else 0 end) Apr.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 4) then 1 else 0 end) may,
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 5) then 1 else 0 end) June,.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 6) then 1 else 0 end) Jul.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 7) then 1 else 0 end) aug.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 8) then 1 else 0 end) Ms.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 9) then 1 else 0 end) oct.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 10) then 1 else 0 end) nov.
sum (case when trunc (RptDate, 'month') = add_months (trunc (sysdate, 'yyyy'), 11) then 1 else 0 end) dec.
sum (case
When the status not ('Void', 'Pending', 'Error') then 1
otherwise 0 end) Total
Info
When the status not ('Void', 'Pending', 'Error')
Group by ID
order by 2Concerning
Rahul MRC -
Hello.
I have a pivot table, and it should update that I change the value of selectOneChoice. I can only view some data in a PivotTable when I choose a value for the first time in selectOneChoice. If I select another value in the SelectOneChoice the PivotTable that is not updated.
Here is my PivotTable:
Can someone help me?<dvt:pivotTable id="pivotTable1" value="#{bindings.TValoresMatrizEnViewUp1.pivotTableModel}" binding="#{backingBeanScope.backing_valoresMatriz.pivotTable1}" contentDelivery="immediate" var="matrix" visible="false" partialTriggers="::socCodigo" rendered="true" > <dvt:dataCell> <af:inputText value="#{matrix.dataValue}" valueChangeListener="#{backingBeanScope.backing_valoresMatriz.alteraPivot}" autoSubmit="true" partialTriggers="it5" id="it5"/> </dvt:dataCell> </dvt:pivotTable>
My JDeveloper is 11.1.1.4.0
Thank youHi Marcos,
Open your page definition and together in the iterator tag refresh properties = 'always' and cacheResults = "false"...
That that it will solve your problem.
Kind regards
Renan
-
OBIEE 11 g: problem view Pivot.
Hello
I've created a report using the pivot table view. Available to view as below
my guest is the default value of the 2014 fiscal year.
How to show the shop for current month.
I won't show for previous months only for Jan - 15.
Kind regards
Srinivas.
Month (CURRENT_DATE) returns a number, which requires the OP have a column with the number of months in the time dimension.
And ask the OP for the previous month, but I guess that's the previous month, not based on the current date (we are in April and he refers to Jan - 15 as the previous month).
Not knowing what the other columns are available in its dimension of time to produce the value of 'Jan-15' will be easier with the variable repository (and in this case the variable will always be correct based on the latest data loaded into the DB).
-
Table PIVOT (10.2.0.4.0) problem
Hi all!
Given the following data set:
Using only SQL and avoiding scalar subqueries, how can I get the data to display as well?CREATE TABLE unpivoted ( id NUMBER, typ VARCHAR2 (30), val VARCHAR2 (30) ); INSERT INTO unpivoted VALUES (1, 'A', 'A123456'); INSERT INTO unpivoted VALUES (1, 'B', 'B455245'); INSERT INTO unpivoted VALUES (2, 'A', 'A835666'); INSERT INTO unpivoted VALUES (2, 'B', 'B126832'); INSERT INTO unpivoted VALUES (2, 'C', 'C123456'); INSERT INTO unpivoted VALUES (3, 'C', 'C545662'); INSERT INTO unpivoted VALUES (3, 'D', 'D525254'); INSERT INTO unpivoted VALUES (3, 'E', 'E636656');
I understand that it probably involves some kind of operation of pivot, but I'm just not smart enough to apply the examples I've seen elsewhere in my data!ID A B C D E ===== ======== ======== ======== ======== ======= 1 A123456 B455245 <NULL> <NULL> <NULL> 2 A835666 B126832 C123456 <NULL> <NULL> 3 <NULL> <NULL> C545662 D525254 E636656
Thank you very much!Hello
Welcome to the forum!
In any version (Oracle 8.1 or higher) you can do this way:
SELECT id , MIN (CASE WHEN typ = 'A' THEN val END) AS a , MIN (CASE WHEN typ = 'B' THEN val END) AS b , MIN (CASE WHEN typ = 'C' THEN val END) AS c , MIN (CASE WHEN typ = 'D' THEN val END) AS d , MIN (CASE WHEN typ = 'E' THEN val END) AS e FROM unpivoted GROUP BY id ORDER BY id ;
Many examples you saw maybe used to COUNT or SUM instead of MIN. You can use a function of aggregation with this technique.
For more info on pivots, see the FAQ forum {message identifier: = 9360005}
Thanks for posting the CREATE TABLE and INSERT statements; It's really useful!
-
Problem with the conditional formatting according to pivot
Hi all
OBIEE version 10.1.3.3.3
I have a measurement with the following condition column
Measure:
-Case when DATE < VALUEOF ("CC_DATE") and the actual amount of another amount, then end
Here CC_DATE is variable repository
I created a column duplicated by the following condition
Double column:
BOX WHEN Date < VALUEOF("CC_DATE") then end if 0-1
And try to use duplicate column in a measure of conditional formatting, however I do not succeed
any suggestion to solve this problem?
Thank you
SMASMA,
Check the link below if you want to put in shape measures based on the intersection of the dimension. A variant of the above link.
http://www.obinotes.com/2010/10/format-cellmeasure-value-based-on-row.htmlJ
-bifacts
http://www.obinotes.com -
All (running 11.2 OEL on 5),
I'm fighting figuring how to get the result I want to with the following data:
Here's what I would get. The column date 10 - Jun 10 - Jul is 'dynamic', and there will be a new column each month.CREATE TABLE REGION_LOOKUP ( REGION_ID NUMBER NOT NULL ENABLE, REGION VARCHAR2(5) NOT NULL ENABLE, PRIMARY KEY ("REGION_ID") ENABLE ) / CREATE TABLE IND_REVENUE ( ID NUMBER, IND_REV_DATE VARCHAR2(30), IND_REVENUE NUMBER, REGION_ID NUMBER, CONSTRAINT IND_REVENUE_PK PRIMARY KEY (ID) ENABLE ) / INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(1,'EMEA'); INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(2,'LAD'); INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(3,'APAC'); INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(4,'NAS'); INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(5,'JAPAN'); / INSERT INTO IND_REVENUE VALUES(1,'10-Jun',73.10,4); INSERT INTO IND_REVENUE VALUES(2,'10-Jul',49.30,4); INSERT INTO IND_REVENUE VALUES(3,'10-Jun',3.20,2); INSERT INTO IND_REVENUE VALUES(4,'10-Jul',0.30,2); INSERT INTO IND_REVENUE VALUES(5,'10-Jun',28.60,3); INSERT INTO IND_REVENUE VALUES(6,'10-Jul',12.40,3); INSERT INTO IND_REVENUE VALUES(7,'10-Jun',64.00,1); INSERT INTO IND_REVENUE VALUES(8,'10-Jul',19.80,1); INSERT INTO IND_REVENUE VALUES(9,'10-Jun',6.60,5); INSERT INTO IND_REVENUE VALUES(10,'10-Jul',4.70,5); /
I think something like that (I'm stuck) but of course, this does not at all and is also hardcoded regarding columns.Region 10-Jun 10-Jul Total APAC $28.6 $12.4 $41.0 EMEA $64.0 $19.8 $83.8 JAPAN $6.6 $4.7 $11.3 LAD $3.2 $0.3 $3.5 NAS $73.1 $49.3 $122.4 Total $175.5 $86.5 $262.0
All great ideas?select rn, 10-Jun, 10-Jul, (10-Jun + 10-Jul) as Total from (select RL.REGION_NAME as rn, RL.REGION as re, IR.IND_REVENUE as rev from REGION_LOOKUP RL, IND_REVENUE IR where IR.region_id = RN.region_id) pivot (SUM(rev) for rn in ('10-Jun' as 10-Jun, '10-Jul' as 10-Jul))
See you soon,.
Andy
Fixed the instructions insert, sorry about that. Copy and paste before the coffee is not good.Hi, Andy.
A Tael says:
A nice solution,Thanks, but what solution do you mean? There were at least 4 different solutions on this page.
but is there a way to avoid the queue to a file?
Do you mean the dynamic SQL solution? Yes, the coil is just a way to make the dynamic SQL statements.
In SQL * more you can write the variable part of the query to a substitution variable (see below).
In PL/SQL, you can assemble a select in VARCHAR2 variable.PROMPT ========== 2. Dynamic Pivot using Substitution Variable ========== -- ***** Preliminary Query: ***** COLUMN sql_txt_col NEW_VALUE sql_txt WITH all_jobs AS ( SELECT DISTINCT job , DENSE_RANK () OVER (ORDER BY job) AS r_num FROM scott.emp ) SELECT SYS_CONNECT_BY_PATH ( job || ''' THEN 1 END) AS ' || job || '_CNT' || CHR (10) -- Newline, for legibility only , ', COUNT (CASE WHEN job = ''' -- Delimiter, goes before each entry ) AS sql_txt_col FROM all_jobs WHERE CONNECT_BY_ISLEAF = 1 START WITH r_num = 1 CONNECT BY r_num = PRIOR r_num + 1 ; -- ***** Main Query ***** SELECT deptno &sql_txt -- Ends with newline, so occupy that line FROM scott.emp GROUP BY deptno ORDER BY deptno ; /* EXPLANATION: Using a substitution variable is very similar to using a script. The main difference is that the output of the preliminary query has to go into one row. This is done with SYS_CONNECT_BY_PATH, and getting that requires that the jobs be numbered with consecutive integers, 1, 2, 3, ... which we get from DENSE_RANK. The NEWLINE character was added just to make the output line easier to read during debugging. */
-
Calculating pivot table problem
Hello..
PivotTable using separate columns for calculation... How to avoid it. ?
For ex:
My database of records are like
region date_id___amt_
01012009 1000 North
01012009 1000 North
01012009 1000 North
01012009 1000 South
01022009 1000 North
01022009 1000 South
01022009 1000 South
My pivot table design is
Line: region
Measure: Amt
Column: Date_id
I get a response such as
___Amt
01012009 01022009 _
_ Of the 1000 1000 North
_ Of the 1000 1000 South
But I need an output like
___Amt
01012009 01022009 _
_ Of the 3000 1000 North
1000 South _ 2000
I think that PivotTable has taken a distinct value for the calculation...
How could I get above exit... ?
Published by: Mohan 8732779 on September 1, 2009 04:03Mohan,
What I got from above, is that you need a sum of the column. To change the aggregation behavior for amt column to say you said the aggregation would be separate. Just change to change the formula in sum, that it looks like something like this flat is what you want to achieve is not it?
By,.
Murielle. -
create the table mytable
(
name varchar2 (50).
name varchar2 (50)
)
Insert the table mytable values ('mary', 'john')
Insert the table mytable values ('mary', 'baby')
Insert the table mytable values ('mary', 'lady')
Insert the table mytable values ('sean', 'kate')
Insert the table mytable values ('sean', 'terry')
Insert the table mytable values ('kate', 'tom')
Insert the table mytable values ('kate', 'lary')
.
.
.
my result of the query is
last name first name
Jean-Marie
baby Marie
Lady Mary
Sean kate
Sean Terry
Tom Kate
Kate lary
I want to like this
Mary kate sean
John tom kate
baby terry lary
Lady
It's not all data.
the data are changeable.there are 3 name as name like sean John 2 2 lik kate and it will be 5 name like paul... I want as column name and surname as the data...
Thanks for your help...
Hello
Try this:
WITH number_rows AS ( SELECT name , surname , ROW_NUMBER () OVER ( PARTITION BY name ORDER BY surname ) AS r_num FROM mytable ) SELECT r_num , MAX (CASE WHEN name = 'mary' THEN surname END) AS mary , MAX (CASE WHEN name = 'sean' THEN surname END) AS sean , MAX (CASE WHEN name = 'kate' THEN surname END) AS kate FROM number_rows GROUP BY r_num ORDER BY r_num;
The output is not quite what you asked:
. R_NUM MARY SEAN KATE ---------- ---------- ---------- ---------- 1 baby kate lary 2 jon terry tom 3 lady
You do not have to display r_num: I showed just to make things easier to understand.
If the output should really include "Jean" rather than "jon", or if it should appear above 'baby', rather than below, so please explain.If the names in columns ("Mary", "sean" and "kate" in your sample data) should be determined at run time, you need dynamic SQL statements to generate a statement like the one above.
The script below shows one way to do this in SQL * more./* How to Pivot a Table with a Dynamic Number of Columns This works in any version of Oracle The "SELECT ... PIVOT" feature introduced in Oracle 11 is much better for producing XML output. Say you want to make a cross-tab output of the scott.emp table. Each row will represent a department. There will be a separate column for each job. Each cell will contain the number of employees in a specific department having a specific job. The exact same solution must work with any number of departments and columns. (Within reason: there's no guarantee this will work if you want 2000 columns.) Case 0 "Basic Pivot" shows how you might hard-code three job types, which is exactly what you DON'T want to do. Case 1 "Dynamic Pivot" shows how get the right results dynamically, using SQL*Plus. (This can be easily adapted to PL/SQL or other tools.) */ PROMPT ========== 0. Basic Pivot ========== SELECT deptno , COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt , COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt , COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt FROM scott.emp WHERE job IN ('ANALYST', 'CLERK', 'MANAGER') GROUP BY deptno ORDER BY deptno ; PROMPT ========== 1. Dynamic Pivot ========== -- ***** Start of dynamic_pivot.sql ***** -- Suppress SQL*Plus features that interfere with raw output SET FEEDBACK OFF SET PAGESIZE 0 SPOOL p:\sql\cookbook\dynamic_pivot_subscript.sql SELECT DISTINCT ', COUNT (CASE WHEN job = ''' || job || ''' ' AS txt1 , 'THEN 1 END) AS ' || job || '_CNT' AS txt2 FROM scott.emp ORDER BY txt1; SPOOL OFF -- Restore SQL*Plus features suppressed earlier SET FEEDBACK ON SET PAGESIZE 50 SPOOL p:\sql\cookbook\dynamic_pivot.lst SELECT deptno @@dynamic_pivot_subscript FROM scott.emp GROUP BY deptno ORDER BY deptno ; SPOOL OFF -- ***** End of dynamic_pivot.sql ***** /* EXPLANATION: The basic pivot assumes you know the number of distinct jobs, and the name of each one. If you do, then writing a pivot query is simply a matter of writing the correct number of ", COUNT ... AS ..."\ lines, with the name entered in two places on each one. That is easily done by a preliminary query, which uses SPOOL to write a sub-script (called dynamic_pivot_subscript.sql in this example). The main script invokes this sub-script at the proper point. In practice, .SQL scripts usually contain one or more complete statements, but there's nothing that says they have to. This one contains just a fragment from the middle of a SELECT statement. Before creating the sub-script, turn off SQL*Plus features that are designed to help humans read the output (such as headings and feedback messages like "7 rows selected.", since we do not want these to appear in the sub-script. Turn these features on again before running the main query. */
-
Pivotal Satellite Pro 6100 problem
One of the parties who bear the my monitor broke so I don't support my monitor, is their wherever I can find a replacement for this?
Hi Mike
All necessary and compatible parts can be ordered from the service provider authorized in your country. I imagine that the technician he will order the Toshiba head stock.
Call the guys and ask the parts needed.It s simply ;)
-
How can I rotate an image of a pivot point?
Hello
I have a problem, the rotation VI Imaq only rotate an image at its Center. My problem is that I need a pivot known to this point. How can I achieve this?
Thank you
Francesco.
This message can help?
http://forums.NI.com/T5/LabVIEW/rotate-an-image-by-specified-pixel/TD-p/2570453 -
Hi, I'm trying to customize some controls, but I have a problem with the construction of a button. I replaced the central image by a more realistic appearance and now I want to change the scale to better understand my button again, but I can't put across the 'ladder' after I want to be able to better run the needle and I can't choose the position of the needle. I am attaching the file so you can view and maybe help me to make this more comfortable button thank you!
to customize your Ctrl button, click on the 'key' to display the icon.then of "clips" you can do what you want with the image or the button of properties, including the streching the balance to make pivot 360 degs, maximum range, no ticks, ticks, etc... BTW, reorganize tab is practical by placing objects to the front or the rear of several images
-
I want to communicate between cRIO-9073, and PC, the master will cRIO. Now am with VISAS for communication, my problem is when I write from PC and read in RIO I can do. But when I write of RIO and read from PC I could not able to read. No value is coming. I don't know what I'm missing. Maybe the difference in speed? Do I have to change baud rate? Now, I put to 9600 in the two.
Can someone please help?
Am still not familiar with the serial port signals but I'm trying to help you. Just do a test: disconnect the cable from the RIO and just turned the numbers 2 and 3 of the serial port cable and run both at the same time code in the host. If you receive data properly, then the problem could be with the cable (right or pivot) option.
-
Hello
I have the same problem. The error message appears when I open my browser Google Chrome (Yes, only that browser). The full message is: could not find the file:...\pivot.ini translation [WPCTRL95] will not run.What kind of changes? As far as I know, I did not bring changes of lipids to my computer or programs. The thing is that I for a moment, and I don't recall the exact moment when it appeared.Hello
Please take a look at the thread similar here with a solution as possible.
I hope this helps!
Maybe you are looking for
-
Should which partition I format it?
I am well brought out shape and external drive and do not know what my drive icon, I need to select before clicking Delete. I always click on the second under the external option, please see the attachment. Does this mean that I am only formatting pa
-
Original title: BIOS How to disabling the system in the away mode
-
Menu button gone after update 4.4.2
Hello Because he wasn't in the right topic in my previous post, I created a new thread for this. After you run the update of chrome and firefox do not have the menu button... By pressing the button of recent items quickly shows the menu before closin
-
I am a user of Windows 7 bits (64).Recently my PC (DELL Latitude E6320) crashes randomly, showing a blue screen error DRIVER_IRQL_NOT_LESS_OR_EQUAL Also in my device manager there is an unknown device, details below Can someone help me solve this?
-
Disable reactivate sound when I touch the volume control
Hello, is there a way how to avoid auto reactivate when I change volume upwards or downwards? This is quite annoying... I installed Realtek High Definition Audio drivers, but did not find any checkbox to disable here. Thank you.