Pivot question
How do after a control table that has automated the process completing daily
create table t1_check (check_no number, check_time date, value number); insert into t1_check values (1,sysdate, 1234); insert into t1_check values (1,sysdate -1, 1342); insert into t1_check values (1,sysdate -2, 1341); insert into t1_check values (2,sysdate, 33); insert into t1_check values (2,sysdate-2, 35); insert into t1_check values (3,sysdate, 2000); insert into t1_check values (3,sysdate-1, 2001); insert into t1_check values (3,sysdate-2, 2002); SQL> select * from t1_check; CHECK_NO CHECK_TIM VALUE ---------- --------- ---------- 1 12-AUG-14 1234 1 11-AUG-14 1342 1 10-AUG-14 1341 2 12-AUG-14 33 2 10-AUG-14 35 3 12-AUG-14 2000 3 11-AUG-14 2001 3 10-AUG-14 2002 8 rows selected. SQL>
How to convert rows to columns (pivot? unpivot?) for the data show the race for 10 days in a report. No each control for every day will have a value, where check_no = 2 in. above dataset would show null for the 11th. If any control has a date then need a column by that date so for over 3 days of data it would be something like below.
I don't know the dates beforehand, it will have to be something like (where check_time > trunc (sysdate)-10)
check_no 10 August 14 August 11, 14 12 August 14
1, 1341, 1342, 1341
33 2 < null > 35
3 2002 2001 2000
Thank you
Hello
Here's a way to use the SELECT... Available in Oracle 11 PIVOT function (and more):
WITH got_d_num AS
(
SELECT check_no
TRUNC (SYSDATE) - TRUNC (check_time) AS d_num
value
OF t1_check
WHERE check_time > = TRUNC (SYSDATE) - 9
AND check_time< trunc="" (sysdate)="" +=""> >
)
SELECT *.
OF got_d_num
PIVOT (AMOUNT (value)
FOR (IN) d_num
-- 9 AS d_9
-- , ...
-- ,
2 AS d_2
1 AS d_1
0 LIKE today
)
)
ORDER BY check_no
;
Here, d_1: 1 day ago (that is, yesterday), average d_2 2 days ago and so on. If you want the real date as an alias of column values, you need dynamic SQL statements.
The results I get are not quite what you posted:
CHECK_NO TODAY D_1-D_2
---------- ---------- ---------- ----------
1, 1341, 1342, 1234
2 35 33
3 2002 2001 2000
I assume that you made a typing mistake.
Tags: Database
Similar Questions
-
I'm new to PIVOT queries. I was making reference to the discussion that follows, but ran into a problem.
When I added the XML to format data, I started to have NULL values rather than what I was looking for.
WITH (AS PIVOT_DATA)
SELECT * FROM)
SELECT THE REGION, FCST_PERIOD, PRIME_PART, FINAL_FORECAST
OF XYZ WHERE FCST_PERIOD > = last_day (trunc (sysdate)) + 1 and FCST_PERIOD < = last_day (add_months(sysdate,12)) AND PRIME_PART IN ('BLAH')
)
PIVOT XML (SUM (FINAL_FORECAST) FOR FCST_PERIOD IN (SELECT DISTINCT FCST_PERIOD OF XYZ))
)
SELECT PRIME_PART, REGION,
EXTRACTVALUE(FCST_PERIOD_XML,'/PIVOTSET/ITEM[1]/COLUMN[2]') FCST_PERIOD1,
EXTRACTVALUE(FCST_PERIOD_XML,'/PIVOTSET/ITEM[2]/COLUMN[2]') FCST_PERIOD2,
EXTRACTVALUE(FCST_PERIOD_XML,'/PIVOTSET/ITEM[3]/COLUMN[2]') FCST_PERIOD3
OF PIVOT_DATA;
RESULTS IN:
PRIME_PART REGION FCST_PERIOD1 FCST_PERIOD2 FCST_PERIOD3 BLA MIDWEST (NULL) (NULL) (NULL) BLA WEST-NV (NULL) (NULL) (NULL) BLA SOUTH-EAST (NULL) (NULL) (NULL) BLA WEST-CA (NULL) (NULL) (NULL) BLA SOUTHWEST (NULL) (NULL) (NULL) BLA EAST (NULL) (NULL) (NULL) The second part of my question is how would I do a group when you use a pivot query. When I finished, I've has several parts and would like to group by REGION.
Thank you!
Names of elements and attributes in XML are case-sensitive.
Try with:
EXTRACTVALUE (FCST_PERIOD_XML, ' / PivotSet/item [1] /column [2]') FCST_PERIOD1
There is also a good chance that EXTRACTVALUE is frowned upon in your version. Instead, use XMLQuery or XMLTable.
That being said, using XML PIVOT just to grind it later into a number known columns is pretty useless.
The same can be achieved much more efficiently with regular PIVOT operator (and if necessary analytical function).
Post some examples of data in the table of your database and your final result expected to get useful assistance.
-
I have a query in Oracle 11:
Resultselect to_char(da,'DY-DD') days from ( select rownum -1 + to_date('2012-10-15','yyyy-mm-dd') da, l from (select level l from dual connect by level <= to_date('2012-10-21','yyyy-mm-dd') - to_date('2012-10-15','yyyy-mm-dd')+1) order by 1)
What I need which is present in a row instead of a column:"DAYS" MON-15 TUE-16 WED-17 THU-18 FRI-19 SAT-20 SUN-21
This should be done with pivot requests? Any suggestion please!MON-15 TUE-16 WED-17 THU-18 FRI-19 SAT-20 SUN-21
Thanks in advance.Hello
user564819 wrote:
I need in 7 different columns.
Oracle version is 11.2.0.1.0. Could you give an example of how to do this with pivot query?Here's one way:
WITH all_days AS ( SELECT LEVEL AS n , TO_CHAR ( TO_DATE ('2012-10-15','yyyy-mm-dd') + LEVEL - 1 , 'DY-DD' ) AS dy_dd FROM dual CONNECT BY LEVEL <= TO_DATE ('2012-10-21','yyyy-mm-dd') + 1 - TO_DATE ('2012-10-15','yyyy-mm-dd') ) SELECT * FROM all_days PIVOT ( MIN (dy_dd) FOR n IN ( 1 AS col_1 , 2 AS col_2 , 3 AS col_3 , 4 AS col_4 , 5 AS col_5 , 6 AS col_6 , 7 AS col_7 , 8 AS col_8 , 9 AS col_9 , 10 AS col_10 ) ) ;
This always displays exactly 10 columns.
If the subquery produces less than 10 dates, then the last columns will be NULL.
If the subquery produces more than 10 dates, will be not shown the 11th (and later versions).There is nothing special about the number 10; You can have any number of columns you want. The number of columns and their names is fixed when you write the query, regardless of what is in the subquery. If you want a dynamic number of columns, or names derived from data, see {message identifier: = 3527823}
-
Question of pivot Table...
Hi all
We use OBIEE11g.I columns like this
month Total_amount pending Prodct name amount (Factcolumn) (fact_column)
XYZ Jan 100 50
200 53 xyz Feb
now, I want to display like this
sale jan Feb
Total_amount 50 100
Amount pending 200 53
WHN I use the pivot column table is displayed columns only it does not display the lines.
Please let me know.
Thank you
SriFirst of all, you need not have a dimension attribute in the application if you want to filter on this topic, so I'll ignore the Product column.
To clarify, we have the following table results: -.
Measure 2 months 1-3
Jan 10 20 30
Feb 40 50 60
Mar 70 80 90You want that it appears as follows: -.
Month Jan Feb Mar
Measure 1 10 40 70
Measure 2 20 50 80
Measure 3 30 60 90In OBIEE 11 g it is obtained simply by dragging the box labels of measure section of columns to the lines of PivotTable section.
Please mark it as useful / replied:
Andy. -
Hello
I have a problem using the pivot report function.
I entered under the function one of the column of the report - do - AR AP balance". AP_INV_PAY_AMT-
BOX WHEN "done - AR AP reconcile." AP_PAY_AMT! Is 0 THEN 0 ELSE "done - AR AP balance". AP_INV_PAY_AMT END
When I run this report - I get the value in the same column made - AR AP balance". AP_PAY_AMT contains the value not equal to zero.
Pleas let me know if I'm doing something wrong.
Thank you
PoojakHello
Instead of "!" = "try"less upper and lower of the angular brackets"."
And if it does not, please elaborate further on the conditions.Concerning
Young -
Hi all
I use 10g. Is is possible to display the following using SQL only?
create the table MC_TEST
(Default CURRENT_BALANCE NUMBER (8.2) 0 non-zero,)
NUMBER of CT_CURRENT_BALANCE default 0 not null,.
PRIOR_BALANCE NUMBER (8.2) by default not null, 0
CT_PRIOR_BALANCE NUMBER default 0 not null);
INSERT INTO MC_TEST VALUES (5000,10,2000,20);
Desired format:
Description quantity count
5000 10 CURRENT_BALANCE
2000 20 PRIOR_BALANCE
Thanks for your help.SQL> select 'CURRENT_BALANCE' bal, CURRENT_BALANCE Amount, CT_CURRENT_BALANCE Count 2 from MC_TEST 3 union 4 select 'PRIOR_BALANCE' bal, PRIOR_BALANCE Amount, CT_PRIOR_BALANCE Count 5 from MC_TEST; BAL AMOUNT COUNT --------------- ---------- ---------- CURRENT_BALANCE 5000 10 PRIOR_BALANCE 2000 20
Max
http://oracleitalia.WordPress.com -
Simple (I'm sure) SELECT FROM question - PIVOT
Hello
I have 2 paintings where one contains the IDS and TITLES of BOOKS and other information on the DVD that contains the images that we scan from the book. We have 2 types of DVD: 1 (Type C) containing images of high quality and the other (Type D), web quality images.
So I do not know how to make my query to display the following result
Published by: Roseline September 30. 2009 04:43TABLE PUBLICATION ID | TITLE ----------------------------- 1 | LIFE Magazine 2 | EARTH 3 | The Economist 4 | TIMES 5 | ANIMALS TABLE SERIEDVD ID | ID.TITLE | TYPE | DVD1(the first DVD of the serie) | DVD2 (the last DVD of the serie) ------------------------------------------------------------------------------------------------------------------------------------------------ 1 | 1 | C | 182 | 216 2 | 1 | D | 678 | 679 3 | 2 | C | 1121 | 1245 4 | 2 | D | 700 | 703 5 | 3 | C | 576 | 613 6 | 3 | D | 236 | 256 WANTED RESULT (on one row. If I do a query, I have the result on 2 rows) TITLE | TYPE C First DVD | TYPE C Last DVD | TYPE D - First DVD | TYPE D Last DVD LIFE Magazine | 182 | 216 | 678 | 679 If I do Select P.TITLE, S.TYPE, S.DVD1, S.DVD2 FROM PUBLICATIONS P, SERIEDVD S where P.ID = S.ID.TITLE AND TITLE = 'Life Magazine' I have this result: TITLE | TYPE | First DVD | Last DVD | LIFE Magazine | C | 182 | 216 | LIFE Magazine | D | 678 | 679 | Thanks, Roseline
Hi, Roseline,.
You need to Rotate your result of 2 rows on 1 row:
Select P.TITLE , MIN (CASE WHEN s.type = 'C' THEN s.dvd1 END) AS c_first , MIN (CASE WHEN s.type = 'C' THEN s.dvd2 END) AS c_last , MIN (CASE WHEN s.type = 'D' THEN s.dvd1 END) AS d_first , MIN (CASE WHEN s.type = 'D' THEN s.dvd2 END) AS d_last FROM PUBLICATIONS P , SERIEDVD S where P.ID = S.ID.TITLE AND TITLE = 'Life Magazine' GROUP BY p.title;
Since there is only a value of s.dvd1 or s.dvd2 in each column, it does not matter if we use MIN or MAX.
-
The pivot in Tecra S1 and duplicator?
I would like to use the pivot of my TFT under my Tecra S1 which is anchored.
No chance for this?
See you soon
Lutz
Hello
As far as I know you need a 3rd party software that should be supplied with the monitor.
But it works on the unit not rooted?Also check this post on a similar question:
http://forums.computers.Toshiba-Europe.com/forums/thread.jspa?forumid=5&ThreadId=9726
-
Hi Master,
The syntax of the pivot function can I use several columns in the "IN CLAUSE". Not as in (10,20,30) deptno column values? Please explain to me. If possible... Thanks for giving me an example
Concerning
AR.
Hello
874273 wrote:
Hi Master,
The syntax of the pivot function can I use several columns in the "IN CLAUSE". Not as in (10,20,30) deptno column values? Please explain to me. If possible... Thanks for giving me an example
Concerning
AR.
Of course, you can have several columns in the IN clause. Try it and see.
I don't know what you mean by "not the values of columns as deptno in (10,20,30). You won't want to give values for each of the columns?
Here is an example:
WITH relevant_data AS
(
SELECT EXTRACT (YEAR FROM hiredate) AS hireyear
deptno
work
FROM scott.emp
WHERE job IN ("CLERK", "MANAGER")
)
SELECT *.
OF relevant_data
PIVOT (COUNT (*)
(JOB, deptno) IN ((«GREFFIER», 10) AS clerk_10)
, ('MANAGER', 10) AS manager_10
, ("CLERK", 20) AS clerk_20
, ('MANAGER', 20) AS manager_20
, ("CLERK", 30) AS clerk_30
, ('MANAGER', 30) AS manager_30
)
)
ORDER BY hireyear
;
Output:
HIREYEAR CLERK_10 MANAGER_10 CLERK_20 MANAGER_20 CLERK_30 MANAGER_30
---------- ---------- ---------- ---------- ---------- ---------- ----------
1980 0 0 1 0 0 0
1981 0 1 0 1 1 1
1982 1 0 0 0 0 0
1987 0 0 1 0 0 0
I hope that answers your question.
If not, post an example of what you're trying to do with multiple columns using other commonly available tables, as scott.emp, or a table of your own table (CREATE TABLE and INSERT post instructions). Display the accurate results you want from the data provided and your best attempt at a query.
-
Hello! First of all, the program is awesome and I can see tons of potential here! I just started to play with her and watch the videos. I apologize if this is covered everywhere and I'm still not there, but I can't find how to make layers of items that are not in the default templates. For example, here's my character that I did and I try to configure for ch.
I glued the eyes and head back into the layers of the appropriate model. I added the point of origin for the neck and so far, so good. Students move with the head, according to the original pivot point and they don't deform or anything like that. -A quick question here - how to define to what extent students can move in this investment? Can I remember how they shift character as I move my eyes on the camera? As a control of tolerance or the setting of the movement? This is perhaps related to the size of the eyeball? I left those.
Okay, back to the main question. Then head and the eyes move based on the origin and don't deform when moving them.
Now I wanted to add a few layers of group head above the eyes and face saving. I would like to add lines on eyes, the façade, the dome of glass, etc. I create layers and dropped, as follows:
I guess since they are in the leading group that they would move related to other items, however, they shift and warp, strangely, as follows:
The lines remain with the façade, which is good, but the lines and front independent rotation of the eyes and face back and then start to deform from the point of origin and great stretch if I, the puppeteer, closer, or farther from the camera. How to make them all move together and not string? Also, I noticed that some photoshop layer effects didn't import, like having a layer set as 'Overlay' transparency. Is it possible to define in Ch or not yet? I wish that the lines to fix to overlay the eyes. I also need the transparent glass dome.
Sorry for dropping a ton here! If there is a tutorial or something that already explains this, I would be happy to follow the link! Great program even once, I can't wait to understand better!
> How to make them for all move them around together and not string?
To get a bunch of things to move together, place them in the same group at PS. Make sure that the group is set to deform independently (i.e. ' + ' before the name of the PS Group, or check the Warp option independently in Ch when that group is selected) and make sure that the things inside the group are not be moved in directions different (or moved at all). For example if right eyebrow and left eyebrow were in this group, they would warp things in the group as you move your eyebrows. If only one thing is moved (as a handle from the head, for example), then the Group should move as one. But you can also have groups within your group and have their value chain regardless of having them akin to the group but does not deform it. This is a common way to have eyebrows - they move with the head, but also independently floating above it. Each group set to deform independently can also specify handle in its parent, it must join (popup under Warp regardless).
> Also, I noticed that some photoshop layer effects didn't import, like having a layer set as 'Overlay' transparency. Is it possible to define in Ch or not yet?
Ch does not yet support all PS layer options. Hearing from you which are the most important help us prioritize.
-
I finally got Pivot to work properly in 11.2 using an associative array and creating columns in the IN clause dynamically the data to rotate.
So now I have 300 + the columns of the 'Y', or Null. Of course, that happened because the table source lacked data for each combination of key and column.
I call this "sparse data.
The question is: what is the most effective way to replace all nulls with "N"?
(1) build the table source of Pivot with inserts and a value of "N" for key/column combinations
I guess I would need to apply a Cartesian join to create a table of all combinations and the join to the original
to determine what combos are missing and that result set for the insert.
(2) perform an UPDATE for each column 300 + replace all nulls with "N".
The function of TRANSFORMATION of Data Miner is for is incredibly inefficient.
I've written a PL/SQL procedure that allows to convert all nulls any value for the columns selected by the corresponding model.
That turned out to be much more effective.
-
Description:
I m referring to the Oracle tutorial http://docs.Oracle.com/JavaFX/2/transformations/jfxpub-transformations.htm using the transformations.zip source code, which is available for download on this page. I Don t understand why they Center the xylophone in space 3D like this and why they calculate the pivot (reverse) using translations. So they are creating a large number of groups, including rectangles, representing the xylophone, in addition to finally to a group called "cam".
class Cam extends Group { Translate t = new Translate(); Translate p = new Translate(); Translate ip = new Translate(); Rotate rx = new Rotate(); { rx.setAxis(Rotate.X_AXIS); } Rotate ry = new Rotate(); { ry.setAxis(Rotate.Y_AXIS); } Rotate rz = new Rotate(); { rz.setAxis(Rotate.Z_AXIS); } Scale s = new Scale(); public Cam() { super(); getTransforms().addAll(t, p, rx, rz, ry, s, ip); } } final Cam camOffset = new Cam(); final Cam cam = new Cam(); ... camOffset.getChildren().add(cam); ... final Scene scene = new Scene(camOffset, 800, 600, true); ...
The Group "cam" is added to another group called "camOffset", which is added to the 'scene' as root the node.
Until there , everything is understandable to me, but there is a method, called "frameCam (.)" which calls 4 other methods: ""
public void setCamOffset(final Cam camOffset, final Scene scene) { double width = scene.getWidth(); double height = scene.getHeight(); camOffset.t.setX(width/2.0); camOffset.t.setY(height/2.0); } //========================================================================= // setCamScale //========================================================================= public void setCamScale(final Cam cam, final Scene scene) { final Bounds bounds = cam.getBoundsInLocal(); final double pivotX = bounds.getMinX() + bounds.getWidth()/2; final double pivotY = bounds.getMinY() + bounds.getHeight()/2; final double pivotZ = bounds.getMinZ() + bounds.getDepth()/2; double width = scene.getWidth(); double height = scene.getHeight(); double scaleFactor = 1.0; double scaleFactorY = 1.0; double scaleFactorX = 1.0; if (bounds.getWidth() > 0.0001) { scaleFactorX = width / bounds.getWidth(); // / 2.0; } if (bounds.getHeight() > 0.0001) { scaleFactorY = height / bounds.getHeight(); // / 1.5; } if (scaleFactorX > scaleFactorY) { scaleFactor = scaleFactorY; } else { scaleFactor = scaleFactorX; } cam.s.setX(scaleFactor); cam.s.setY(scaleFactor); cam.s.setZ(scaleFactor); } //========================================================================= // setCamPivot //========================================================================= public void setCamPivot(final Cam cam) { final Bounds bounds = cam.getBoundsInLocal(); final double pivotX = bounds.getMinX() + bounds.getWidth()/2; final double pivotY = bounds.getMinY() + bounds.getHeight()/2; final double pivotZ = bounds.getMinZ() + bounds.getDepth()/2; //*1* cam.p.setX(pivotX); cam.p.setY(pivotY); cam.p.setZ(pivotZ); //*1* //*2* cam.ip.setX(-pivotX); cam.ip.setY(-pivotY); cam.ip.setZ(-pivotZ); //*2* } //========================================================================= // setCamTranslate //========================================================================= public void setCamTranslate(final Cam cam) { final Bounds bounds = cam.getBoundsInLocal(); final double pivotX = bounds.getMinX() + bounds.getWidth()/2; final double pivotY = bounds.getMinY() + bounds.getHeight()/2; cam.t.setX(-pivotX); cam.t.setY(-pivotY); }
If the method ' setCamScale (...) 'is understandable,' setCamOffset (...) ' puts the root node ('camOffset') in the center of the screen, but I Don t understand the 2 following methods at all. Of course, the child ("cam") is not centered, by putting just the root node ('camOffset') in the center of the screen, but how they focus the xylophone / "cam" and set the pivot, using translations:
Questions:
- Why they use 3 different translations (', 'ip', 'p')?
- Referring to ' setCamPivot (...) ': Why they are the first translation of 'cam.p' to "pivotX", 'pivotY' and 'pivotZ' and then 'cam.ip' to '-pivotX', '-pivotY' and '-pivotZ' (marked in the source code with * 1 * and * 2 *)? Should he not just put the Group at his position, where it has been positioned before, as if the method has never been called? That would be my guess, because I expect that an object is placed in the same position as before, if I first move with the values X, Y, Z and then return with the same values - X, - Y, - Z in the opposite direction.
- Even with the method ' setCamTranslate (...) ' ': Why use another translation "cam.t", moving the Group ("cam") with the same values "-pivotX', '-pivotY' (and not '-pivotZ'), which they used in the"setCamPivot (...) method `?
Annotations:
Of course it works, the xylophone is located in the center of the screen and could turn perfectly, without change of rotation point / pivot point, but I Don t understand how they did it. I read everything about layoutBound, boundsInLocal, boundsInParent, blogs about page layout and page layout goes into javaFX https://blogs.oracle.com/jfxprg/entry/the_peculiarities_of_javafx_layout and http://amyfowlersblog.wordpress.com/2011/06/02/javafx2-0-layout-a-class-tour/ and finally a large number of questions to stackoverflow, but I still Don t understand the meaning behind the methods stated.
Before the call of ' frameCam (...) ', they ask:
double halfSceneWidth = 375; // scene.getWidth()/2.0; double halfSceneHeight = 275; // scene.getHeight()/2.0; cam.p.setX(halfSceneWidth); cam.ip.setX(-halfSceneWidth); cam.p.setY(halfSceneHeight); cam.ip.setY(-halfSceneHeight);
I deleted these lines, because it doesn't change anything.
The base in place, is that there are three defined different rotations, one around each axis. Of course, these could be combined into a single rotation, but doing so would make the geometry in the mouse dragging very complex managers. As it is, the degree of rotation around each axis can be calculated and changed independently.
In general, the rotations are defined by an angle, an axis and a (pivot) point. The axis is a 3D vector and goes through the pivot point; the rotation is around this axis through that point.
In the configuration in the example, the pivot of each of the individual rotations is set to the default (0,0,0). Because we really want the rotation to be around the center of the group, not the original, the Group translates first point appropriate pivot (ip), the rotations are applied then (around (0,0,0) after translation by ip), then the group is reflected in its location of origin (p). These operations are not commutative, yes show ip, then the rotation, then p is not the same as when you run ip, then p, then the rotation (in the second, ip and p would cancel and rotation would be about (0,0,0) instead of around the Center).
For good measure, there is a scale, that is also applied after ip (so that scaling occurs from the Center, not the original) and then a final translation.
The final effect is that there is a lot of transformations that can be controlled independently. There is a scale (s), a rotation about each axis (rx, ry, rz), and a translation (t). The p in translations and its inverse ip are just "housekeeping" to ensure that rotation and scaling are done from the center of the screen, instead of (0,0,0).
So:
Why they use 3 different translations (', 'ip', 'p')?
p and ip are translations for the rotation and scaling are done from the Center and not to the origin. t is a general translation, the user sees.
Referring to ' setCamPivot (...) ': Why they are the first translation of 'cam.p' to "pivotX", 'pivotY' and 'pivotZ' and then 'cam.ip' to '-pivotX', '-pivotY' and '-pivotZ' (marked in the source code with * 1 * and * 2 *)? Should he not just put the Group at his position, where it has been positioned before, as if the method has never been called?
He puts the group to its original position, but other changes are between p and ip. These transformations behave differently (in a planned way) because the group is translated when they are applied.
Even with the method ' setCamTranslate (...) ' ': Why use another translation "cam.t", moving the Group ("cam") with the same values "-pivotX', '-pivotY' (and not '-pivotZ'), which they used in the"setCamPivot (...) method `?
The t values are changed in the mouse Manager (with alt-middle mouse button-drag, which I can't test actually using my trackpad...). As you have noted, the effect of p and IP translation cancel out, so we end up with t, which can be changed by the user. They could have combined t and p a single transformation, but updated since the mouse Manager would have been more delicate, and the intent of the code would be less clear.
-
Hello. I have still some difficulties using pivot. =(
I have the following tables:
USER - THE LIST OF ALL USERS
USERROLE - LIST DESIGNATED FOR EACH USER ROLE
ROLEENTITY - WHOLE ENTITY BY THE ROLE OF THE LIST
ENTITY - ENTITY LIST
AUDITUSER - TABLE AUDIT FOR EACH USER MAINTAINED/UPDATED
goal is to get a list of all users maintained the previous day. and I want the entities be converted into columns (using the pivot).
so if a user has been kept twice yesterday, there will be 2 separate newspapers.
TABLE: USER
LOGINID FIRSTNAME LASTNAME
ALVIN JOSEPH 1
ERWIN 2 CO
TABLE: USERROLE
ID LOGINID ROLEID
1 1 45
2 2 33
TABLE: ROLEENTTITY
ID ROLEID ENTITYID
1 45 1
2 45 3
3-33-1
4 33 4
TABLE: ENTITY
ID ENTITYNAME
1. CREATE USER
2 REMOVE USER
RESET 3 USER
4 EMAIL
5 REPORTS
TABLE: AUDITUSER
ID PERFORMEDBY ACTIONPERFORMED DATE LOGINID
1 ADMIN1 CREATE 04/07/13 ALVIN
UPDATED 04/07/13 ALVIN ADMIN2 2
3 ADMIN1 UPDATE 04/07/13 ALVIN
4 ADMIN1 CREATE 04/07/13 ERWIN
ADMIN1 5 UPDATE 04/07/13 ERWIN
EXPECTED RESULT
LOGINID CREATE USER DELETE USER RESET USER EMAIL REPORTS MAINTAINED BY ACTION
ALVIN YES NO YES CREATE NO ADMIN1 NO.
ALVIN NO YES NO YES NO NO. UPDATE ADMIN2
ALVIN NO YES NO YES NO NO. UPDATE ADMIN1
ERWIN YES NO NO YES CREATE NO ADMIN1
ERWIN YES NO NO YES NO ADMIN1 UPDATE(1) correction:
Instead ofWHEN TRUNC (a.date) = TO_DATE (TO_CHAR (SYSDATE - 1, 'DD-MM-YYYY'), "DD-MM-YYYY")
use
WHEN TRUNC (a.date) = trunc (sysdate)-1
(2) on the question: I have just check the own query and it works correctly, show your selection
WITH usr(ID,USERNAME) AS ( SELECT 1, 'ALVIN' FROM dual UNION ALL SELECT 2, 'ERWIN' FROM dual ), USERROLE(ID, LOGINID, ROLEID) AS ( SELECT 1, 1, 45 FROM dual UNION ALL SELECT 2, 2, 33 FROM dual ), ROLEENTITY(ID, ROLEID, ENTITYID) AS ( SELECT 1, 45, 1 FROM dual UNION ALL SELECT 2, 45, 3 FROM dual UNION ALL SELECT 3, 33, 1 FROM dual UNION ALL SELECT 4, 33, 4 FROM dual ), ENTITY(ID, ENTITYNAME) AS ( SELECT 1, 'CREATE USER' FROM dual UNION ALL SELECT 2, 'DELETE USER' FROM dual UNION ALL SELECT 3, 'RESET USER' FROM dual UNION ALL SELECT 4, 'Email' FROM dual dual UNION ALL SELECT 3, 'REPORTS' FROM dual ), AUDITUSER (ID, PERFORMEDBY, ACTIONPERFORMED, DAT, LOGINID) AS (SELECT 1, 'ADMIN1', 'CREATE', TRUNC(SYSDATE)-3, 'ALVIN' FROM dual UNION ALL SELECT 2, 'ADMIN2', 'UPDATE', TRUNC(SYSDATE)-1, 'ALVIN' FROM dual UNION ALL SELECT 3, 'ADMIN1', 'UPDATE', TRUNC(SYSDATE)-2, 'ALVIN' FROM dual UNION ALL SELECT 4, 'ADMIN1', 'CREATE', TRUNC(SYSDATE)-3, 'ERWIN' FROM dual UNION ALL SELECT 5, 'ADMIN1', 'UPDATE', TRUNC(SYSDATE)-3, 'ERWIN' FROM dual ) SELECT username, NVL2(EMAIL,'YES','NO') email, NVL2(CREATEUSER,'YES','NO') CREATEUSER, NVL2(delete_user,'YES','NO') delete_user, NVL2(reset_user,'YES','NO') reset_user, NVL2(REPORTS,'YES','NO') REPORTS, a.ACTIONPERFORMED, a.dat FROM (SELECT U.*, E.ENTITYNAME FROM ENTITY E JOIN ROLEENTITY RE ON RE.ENTITYID = E.ID JOIN USERROLE UR ON UR.ROLEID = RE.ROLEID JOIN USR U ON U.ID = UR.LOGINID) PIVOT(MIN(ID) FOR ENTITYNAME IN('Email' EMAIL, 'CREATE USER' CREATEUSER, 'DELETE USER' delete_user, 'RESET USER' reset_user, 'REPORTS' REPORTS)) JOIN AUDITUSER a ON a.LOGINID = username AND A.DAT = TRUNC(SYSDATE)-3 ORDER BY 1 ALVIN NO YES NO YES YES CREATE 05.04.2013 ERWIN YES YES NO NO NO UPDATE 05.04.2013 ERWIN YES YES NO NO NO CREATE 05.04.2013
-
Pivot can be used in fast refresh materialized view?
Hi, I have a question about materialized view nested mode fast refresh on Oracle 11 g (It support function of pivot, but oracle 10 g doesn't support).
When I created, he throws "ORA-12015: cannot create a view fast refresh materialized by a complex query.
Then I used dbms_mview.explain_mview to see reason, and it tell me the following
REFRESH_FAST_AFTER_INSERT ' view inline or subquery in LIST not supported for this type of MV.
Can someone help me, any suggestions will be appreciated
create table empX as select * from scott.emp; alter table empX add constraint PK_empX_empno primary key (empno); --drop MATERIALIZED VIEW LOG ON empX; CREATE MATERIALIZED VIEW LOG ON empX with rowid, sequence(empno); --drop MATERIALIZED VIEW mv_empX; CREATE MATERIALIZED VIEW mv_empX REFRESH FAST START WITH SYSDATE NEXT SYSDATE + 1/1440 AS select * from ( select rowid emp_rowid, deptno, job, sal from empX ) PIVOT( max(sal) for job IN ('ANALYST' job1, 'CLERK' job2, 'MANAGER' job3)); --select * from mv_capabilities_table declare lv_sqltext varchar2(4000); begin execute immediate 'truncate table mv_capabilities_table'; lv_sqltext := 'select * from ( select deptno, job, sal from empX ) PIVOT( max(sal) for job IN (''ANALYST'' job1, ''CLERK'' job2, ''MANAGER'' job3)) '; dbms_mview.explain_mview(lv_sqltext,'nested=>TRUE'); commit; end; /
Let me help you...
I have done following and it run/view updated because I just replaced quickly with a complete word, because there are limitations for quickly updatable views:SQL> show user; USER is "SCOTT" SQL> create table empX as select * from scott.emp; Table created. SQL> alter table empX add constraint PK_empX_empno primary key (empno); Table altered. SQL> SQL> --drop MATERIALIZED VIEW LOG ON empX; SQL> CREATE MATERIALIZED VIEW LOG ON empX with rowid, sequence(empno); Materialized view log created. SQL> SQL> --drop MATERIALIZED VIEW mv_empX; SQL> CREATE MATERIALIZED VIEW mv_empX 2 REFRESH COMPLETE WITH rowid 3 START WITH sysdate 4 NEXT SYSDATE + 1/1440 5 AS 6 select * from 7 ( 8 select rowid emp_rowid, deptno, job, sal from empX 9 ) 10 PIVOT( max(sal) for job IN ('ANALYST' job1, 'CLERK' job2, 'MANAGER' job3)); Materialized view created. SQL> select * from mv_empx; EMP_ROWID DEPTNO JOB1 JOB2 JOB3 ------------------ ---------- ---------- ---------- ---------- AAAShcAAEAAAATTAAN 10 1300 AAAShcAAEAAAATTAAE 30 AAAShcAAEAAAATTAAJ 30 AAAShcAAEAAAATTAAC 30 AAAShcAAEAAAATTAAA 20 800 AAAShcAAEAAAATTAAK 20 1100 AAAShcAAEAAAATTAAM 20 3000 AAAShcAAEAAAATTAAD 20 2975 AAAShcAAEAAAATTAAB 30 AAAShcAAEAAAATTAAI 10 AAAShcAAEAAAATTAAL 30 950 EMP_ROWID DEPTNO JOB1 JOB2 JOB3 ------------------ ---------- ---------- ---------- ---------- AAAShcAAEAAAATTAAF 30 2850 AAAShcAAEAAAATTAAG 10 2450 AAAShcAAEAAAATTAAH 20 3000 14 rows selected. SQL> begin 2 dbms_mview.refresh('SCOTT.mv_empx'); 3 end; 4 / PL/SQL procedure successfully completed. SQL> select * from mv_empx; EMP_ROWID DEPTNO JOB1 JOB2 JOB3 ------------------ ---------- ---------- ---------- ---------- AAAShcAAEAAAATTAAN 10 1300 AAAShcAAEAAAATTAAE 30 AAAShcAAEAAAATTAAJ 30 AAAShcAAEAAAATTAAC 30 AAAShcAAEAAAATTAAA 20 800 AAAShcAAEAAAATTAAK 20 1100 AAAShcAAEAAAATTAAM 20 3000 AAAShcAAEAAAATTAAD 20 2975 AAAShcAAEAAAATTAAB 30 AAAShcAAEAAAATTAAI 10 AAAShcAAEAAAATTAAL 30 950 EMP_ROWID DEPTNO JOB1 JOB2 JOB3 ------------------ ---------- ---------- ---------- ---------- AAAShcAAEAAAATTAAF 30 2850 AAAShcAAEAAAATTAAG 10 2450 AAAShcAAEAAAATTAAH 20 3000 14 rows selected. SQL>
So, the answer is Yes, we can use Pivot with Materialized view but:
1 MV must be full refresh.
2 oracle version should be 11 g; of course the pivot is available in Oracle 11 g.If this answers your question, please close the message, otherwise continue.
These links may also be of interest:
http://docs.Oracle.com/CD/B28359_01/server.111/b28313/basicmv.htm#i1007028
http://docs.Oracle.com/CD/B28359_01/server.111/b28313/basicmv.htm#i1007007http://rwijk.blogspot.in/2009/06/fast-refreshable-MATERIALIZED-view.html
And:
Please see if (Note: 179466.1 - view to fast refresh materialized diagnose ORA-12015 / complex queries) help.
Concerning
Girish Sharma -
Convert pivot table to a table in the same answers BI report
Hello
I have a simple BI answers report. I used a PivotTable when in fact I have no aggregate
so it would be faster performance (I said) to use a table for the view, rather than on a pivot table view.
Is there a quick way to convert a pivot table view to a table view, without having to re - select
all the columns all over again?
Thanks a lot for all the replies.
-Greguser1636556 wrote:
Thanks for your reply. How exactly "choose you as ' a table view. At runtime, I get the view composed upwards.
Then change the drop-down menu that says "Compound Layout" and choose "Table" currently? I tried that and
the PivotTable returned at run time. Or do I do 'View Edition' on the existing PivotTable and change something that
for a Table view?Thanks for your help.
-Greg
Compound mode is the "view holds that all views." On the upper right side, you can click on the Red 'X' and remove the Pivot Table view. You can then "Add View", and select the Table view. Compound mode will be your title and Table.
So to answer your question, no, not "change the drop down menu that currently says"Compound Layout"and choose"Table"that takes you only to the view of the Table, because it does not affect the report itself. That's why at run time, you still get the Pivot Table View. Follow my instructions in the previous paragraph. Good luck!
Edited by: David_T December 9, 2011 10:25
Maybe you are looking for
-
How can I change the date of the creation of a document?
I am interested to change manually the date of creating a document. When to use the traditional format of: Touch-t 03052130 I get the error: Touch-t 03052130/primary/Screen\ Shot\ 2016-02-25\ at\ 11.41.39\ AM.jpg touch: out of range or illegal specif
-
Microsoft on a Mac Remote Desktop
I have a user who wants to use a desktop app remotely in distance back to his PC Windows7 of his Macbook pro. I could download and install Microsoft remote desktop 8.0.9 from the Apple app store, but I am unable to connect to the computer, it keeps
-
BlackBerry smartphones nothing doin
Impossible to get the torch 9800 for reply all. Not even to turn it off. Default is "Please enter password", but no screen or keyboard present works. Any ideas for a fix?
-
Semicircle with edge of sharpness
HelloHow can I draw a semi-circle with edge of sharpness?Thank you
-
Muse the notification bar 040 cookie themes Toolbox
qualcuno di voi ha usato "muse themes toolbox 040 cookie notification bar. Come funziona? Preventivamente BLOCCA I cookie prima che da person he website?has anyone of you used "muse . themes Toolbox 040 notice bar. " How does it work? Block Advance c