no aggregation of pivot function
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Hi, thank you very much in advance.
I want to combine two lines into a single line, group by (area_code, team, office_code, supervisorID) - if the collector ID (IS_DESKCALL = 'Y') and collectorID(IS_DESKCALL='N') in the same line. As it is not an aggregation function, so I can't use function pivot in 11g?
/ * Formatted on 05/11/2014 19:34:09 (v5.139.911.3011 PS5) * /.
WITH T AS (SELECT '31012' office_code,)
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204135',
' NO IS_DESKCALL.
'201205000' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '31012' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204135',
'Y' IS_DESKCALL,.
'201205555' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '31012' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204888',
' NO IS_DESKCALL.
'201205000' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '31012' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204888',
'Y' IS_DESKCALL,.
'201205555' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '77777' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204999',
' NO IS_DESKCALL.
'201205023' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '77777' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204999',
'Y' IS_DESKCALL,.
'201205444' COLLECTOR_ID
THE DOUBLE)
SELECT *.
T
The result should be:
office_code area_code team supervisorID collectorID(IS_DESKCALL='Y') collectorID(IS_DESKCALL='N')
31012 00003 1 201204135 201205555 201205000
31012 00003 1 201204888 201205555 201205000
77777 00003 1 201204999 201205444 201205023
As it is not an aggregation function, so I can't use function pivot in 11g?
You can use MIN (or MAX):
select * from t pivot ( min(collector_id) for is_deskcall in ( 'Y' as collector_id_y , 'N' as collector_id_n ) ) ;
Tags: Database
Similar Questions
-
How to use the Pivot function for range group in oracle SQL
Hello
Hello!!!
I need to display the data in the format below. There are 2 columns 1 is State and another is rate.
State < 100 100-199, 200-299 300-399 400-499, 500-599 600-699 700-799 800-899 900-999 > = 1000 Total
AK 1 2 0 4 1 4 4 35 35 4 1 25
AL 0 0 2 27 10 17 35 2 2 35 0 103
AR 0 0 1 0 0 2 2 13 13 2 0 6
AZ 0 1 2 14 2 14 13 3 3 13 0 57
CA 0 0 1 6 2 7 3 4 4 3 0 34
Developed the sub query but unable to use the beach on the pivot function. Please help on this.
(select (SELECT short_description
OF CODE_VALUES
WHERE CODE_TYPE_CODE = ad. STATE_TYPE_IND_CODE
AND VALUE = ad. STATE_CODE
) STATE,
Nr.rate
N-NEUTRAL
c contacts,
announcement of addresses,
xref_contacts_addresses xca,
neutral_rates nr
where n.contact_id = c.contact_id
and n.address_id = ad.address_id
and xca.address_id = ad.address_id
and xca.contact_id = c.contact_id
and nr.contact_id = n.contact_id
and nr.rate_frequency = 'HOUR')Like this
with t as ( select 'AL' state, 12 value from dual union all select 'AL' state, 67 value from dual union all select 'AL' state, 23 value from dual union all select 'AL' state, 12 value from dual union all select 'AL' state, 12 value from dual union all select 'AL' state, 78 value from dual union all select 'AL' state, 34 value from dual union all select 'AL' state, 4 value from dual union all select 'AL' state, 12 value from dual union all select 'AL' state, 15 value from dual union all select 'AZ' state, 6 value from dual union all select 'AZ' state, 123 value from dual union all select 'AZ' state, 123 value from dual union all select 'MA' state, 23 value from dual union all select 'MA' state, 120 value from dual union all select 'MA' state, 456 value from dual union all select 'MA' state, 11 value from dual union all select 'MA' state, 24 value from dual union all select 'MA' state, 34 value from dual union all select 'MA' state, 87 value from dual union all select 'MA' state, 23 value from dual union all select 'MA' state, 234 value from dual union all select 'MA' state, 789 value from dual union all select 'MH' state, 54321 value from dual ) -- End of test data select state, nvl(count(decode(value, 0, 0)), 0) "<100", nvl(count(decode(value, 1, 1)), 0) "100-199", nvl(count(decode(value, 2, 2)), 0) "200-299", nvl(count(decode(value, 3, 3)), 0) "300-399", nvl(count(decode(value, 4, 4)), 0) "400-499", nvl(count(decode(value, 5, 5)), 0) "500-599", nvl(count(decode(value, 6, 6)), 0) "600-699", nvl(count(decode(value, 7, 7)), 0) "700-799", nvl(count(decode(value, 8, 8)), 0) "800-899", nvl(count(decode(value, 9, 9)), 0) "900-999", nvl(count(decode(value, 10, 10)), 0) ">=1000" from ( select state, case when value < 100 then 0 when value between 100 and 199 then 1 when value between 200 and 299 then 2 when value between 300 and 399 then 3 when value between 400 and 499 then 4 when value between 500 and 599 then 5 when value between 600 and 699 then 6 when value between 700 and 799 then 7 when value between 800 and 899 then 8 when value between 900 and 999 then 9 when value >= 1000 then 10 end value from t ) group by state
-
help in the application without using the pivot function
Hi gurus,
Can you please help write the query without using the PIVOT function.
Thanks in advance!...WITH indata AS (SELECT 1 sn, '123:456,789,323:456,213,344,345:5454' x from dual UNION ALL SELECT 2, 'abcd:fgrfr,rfrf,rfred,tg:tg,tg:ophhh,op,vdfgbh:poijn' x from dual), instr AS (SELECT a.SN, rownum RN, B.column_value || CASE WHEN B.column_value NOT LIKE '%:%' THEN ':' END column_value FROM indata a, TABLE(CAST(multiset (SELECT trim(SUBSTR(x, (CASE LEVEL WHEN 1 THEN 1 ELSE instr(x, ',', 1, LEVEL - 1) + 1 END), (CASE instr(x, ',', 1, LEVEL) WHEN 0 then 4000 ELSE instr(x, ',', 1, LEVEL) - 1 - (CASE LEVEL WHEN 1 THEN 0 ELSE instr(x, ',', 1, level - 1) END) END))) FROM dual CONNECT BY level <= LENGTH(x) - LENGTH(REPLACE(x, ',', '')) + 1) AS sys.odcivarchar2list)) b) SELECT col1_val2, col1_val1, col2_val2, col2_val1, systimestamp FROM (select SN, ROW_NUMBER() over(partition by SN order by RN) RN, SUBSTR(column_value, INSTR(column_value, ':') + 1) VAL1, substr(column_value, 1, instr(column_value, ':') - 1) val2 FROM instr ) PIVOT(MAX(VAL1) VAL1, MAX(VAL2) VAL2 FOR SN IN(1 as col1,2 as col2));
Any help would be appreciated.user590978 wrote:
Can you please help write the query without using the PIVOT function.
with indata as ( select 1 sn,'123:456,789,323:456,213,344,345:5454' x from dual union all select 2, 'abcd:fgrfr,rfrf,rfred,tg:tg,tg:ophhh,op,vdfgbh:poijn' x from dual ), t1 as ( select x from indata where sn = 1 ), t2 as ( select x from indata where sn = 2 ), t3 as ( select level lvl, substr( x, instr(',' || x,',',1,level), instr(x || ',',',',1,level) - instr(',' || x,',',1,level) ) col1 from t1 connect by level <= length(x) - length(translate(x,'A,','A')) + 1 ), t4 as ( select level lvl, substr( x, instr(',' || x,',',1,level), instr(x || ',',',',1,level) - instr(',' || x,',',1,level) ) col2 from t2 connect by level <= length(x) - length(translate(x,'A,','A')) + 1 ), t5 as ( select lvl, substr(col1,1,instr(col1 || ':',':') - 1) col1_val1, substr(col1,instr(col1 || ':',':') + 1) col1_val2 from t3 ), t6 as ( select lvl, substr(col2,1,instr(col2 || ':',':') - 1) col2_val1, substr(col2,instr(col2 || ':',':') + 1) col2_val2 from t4 ) select col1_val1, col1_val2, col2_val1, col2_val2, systimestamp from t5 full join t6 on ( t6.lvl = t5.lvl ) order by coalesce(t5.lvl,t6.lvl) / COL1_VAL1 COL1_VAL2 COL2_VAL1 COL2_VAL2 SYSTIMESTAMP ---------- ---------- ---------- ---------- ------------------------------------- 123 456 abcd fgrfr 23-OCT-12 11.50.12.015000 AM -04:00 789 rfrf 23-OCT-12 11.50.12.015000 AM -04:00 323 456 rfred 23-OCT-12 11.50.12.015000 AM -04:00 213 tg tg 23-OCT-12 11.50.12.015000 AM -04:00 344 tg ophhh 23-OCT-12 11.50.12.015000 AM -04:00 345 5454 op 23-OCT-12 11.50.12.015000 AM -04:00 vdfgbh poijn 23-OCT-12 11.50.12.015000 AM -04:00 7 rows selected. SQL>
SY.
-
Pivot / without pivot function-example
Hello
Can someone explain to me the differece between pivot and pivot function.
Concerning
SAHello
Please find below the queries for your reference. Function pivot is introduced by from 11 g. Before that, we can solve the problems with the 'breaks', 'decode' functions.
But the pivot and unpivot functions are very flexible to Oracle11g to get the line to columns and vice versa outputs.Oracle 10g
***********
Select the task,
sum (case when deptno = 30
then the sal
Another null
end) dept30
sum (case when deptno = 10
then the sal
Another null
end) dept10
sum (case when deptno = 20
then the sal
Another null
end) dept20
sum (case when deptno = 40
then the sal
Another null
end) dept40
Sum (SAL) Total_Sal
WCP
Working GroupOracle 11g
**********Select the task, dept_30, dept_10, dept_20, total_sal
de)
Select work,
DEPTNO,
SAL,
Sum (SAL) on total_sal (work partition)
WCP
)
pivot)
Sum (SAL)
to deptno in)
30 as dept_30,
10 as dept_10,
20 as dept_20));I hope that you understand the above examples...!
KPR
-
Hello
I have recipes at the quarterly level and backlog at the level of monthly as follows
Quarter - recipes - backlog
Q1------------------A-----------------------x
-----------------------------------------------y
-----------------------------------------------z
Q2-------------------B----------------------p
-----------------------------------------------q
------------------------------------------------r
The final report I want is a consolidated for orders as follows:
Quarter - recipes - backlog
Q1--------------A----------------x+y+z
Q2--------------B-----------------p+q+r
When I use a table view, it gave me the following report
Quarter - recipes - backlog
Q1------------------A-----------------------x
----------------------A-----------------------y
----------------------A-----------------------z
Q2-------------------B----------------------p
-----------------------B----------------------q
-----------------------B----------------------r
I tried to use PivotTable that gives me a wrong as value below
Quarter - recipes - backlog
Q1--------------A+A+A----------------x+y+z
Q2--------------B+B+B-----------------p+q+r
Pls tell how to achieve my requirement.
Thank you
Souloumiac.
Published by: joelle March 3, 2009 13:32Take a look at the sum (column_name by other_column_name)
Concerning
John
http://obiee101.blogspot.com/ -
Dynamic columns to line (pivot) with no aggregation
Hello
I have browsed the forum, the last days for swivel clues dynamic but couldn't find a solution. I really appreciate advice to guide me in the right direction.
I want the last two columns dynamically converted the last as lines.
Oracle version: 11 GR 2
Is this possible?server client errorset Date ms003 apex1 256 02/01/2012 ms001 apex2 324 01/15/2011 me002 sql001 0 03/11/2011 me001 sql003 12 02/01/2012 . . . . . . . . . . . . . . . . convert it the following : server client 02/01/2012 01/15/2011 03/11/2011 . . . . . ms003 apex1 256 ms001 apex2 324 me002 sql001 0 me001 sql003 12 . . . . . . . .
Thank you
-Abe
Published by: abe50 on February 14, 2012 11:46Hi, Abe,
abe50 wrote:
Hi Frank,.Thanks for a very useful tip. It looks like the example in this thread using the aggregation. I want to Pivot without any aggregation.
-Abe
In pivot, you take the information located on multiple lines and combining lines in a line of output. It's the aggregation; It's exactly what you want to do. Whether you use the old techniques of pivot, the Oracle 11 SELECT... PIVOT function, you must specify aggregate functions.
This does not say that to transform your data. If every result field is derived from only a single entry filed, will take aggregates of groups who have only 1 member. You can use MIN and MAX to get the value of a member. (Since there is only 1 value, MIN and MAX will return the same value.)
In your case, you could do something like this:... PIVOT ( MIN (errorset) FOR dt IN ( DATE '2012-02-01' AS "02/01/2012" , DATE '2011-01-15' AS "01/15/2011" ...
-
Pivot adjust HP w2408 function does not change not as Op Sys Win Vista to Win 7.
1. Monitor: HP w2408. Special model with adjustment of the pivot
2. operating system: has: Windows Vista - pivot adjustment works properly. IS: Windows 7 - setting pivot works at all.
3. error message: no
4. changes: operating system as in point 2 above.
5 setting HP w2408 pivot function did not work since the evolution of the operating system from Windows Vista to Windows 7.
I found the solution to my problem. "My screen" (re: your Start menu) is not supported by HP for Windows 7. However, my display works with Win 7. When my computer was worked on by a local repair shop, apparently the pivot function has been disabled by mistake. Happy news: HP has a great method for the restoration of the pivot function.
http://support.HP.com/us-en/document/c00872993
I copied the above URL when I was on the site of HP.
I hope that solves your problem. I now work in landscape mode (he wanted ArcMap). Normally, I'm in vertical mode; It is ideal for editing large text documents!
LS58
-
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.
-
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.
-
Pivot in 11g producing a keyword error
Hello everyone. :) I am a freshman in SQL and just to get to the track of a blazing function pivot for the section of society, I work in. (it goes without saying, a response of Sesame Street style is not offensive.) We are literally moving to 11 g (11.2.0.1.0). Unfortunately, none of our more experienced programmers now anything on the pivot function. It's not really surprising to me since we worked in 10g. In any case, I use the SQL Developer 3.0.04 version which I know is not the newest, but I do not yet have permission to upgrade. I used http://www.oracle-developer.net/display.php?id=506# to me as much as I am about this feature. Please , could someone help me see what Miss me?
The script that I have problems with is:
SELECT *.
Of
(SELECT
begin_month,
begin_yr,
uut_part_num,
uut_part_description
Of
Cris.serial_num_rpt_view
PIVOT (SUM (wonum) AS WO_Count
FOR begin_yr AS year, begin_month IN
(AS of January 01,
02. IN February,.
03 MARCH
04 IN April,
05 MAY,
06 in June,
07. IN July,.
August 08,
September 09,
10 IN October,
In November, 11
(12 DECEMBER))
WHERE
date_reported > = to_timestamp (: v_bDate, ' MM/DD/YYYY')
AND date_reported < = to_timestamp (: v_eDate, ' MM/DD/YYYY')
AND Association = 'HORN')
The site WHERE AS SUPERIOR (BOX WHEN: v_SITE IS NULL THEN '%' ELSE: v_SITE END)
AND TFA as SUPERIOR (BOX WHEN: v_TFA IS NULL THEN '%' ELSE: v_TFA END)
AND SUBTFA as SUPERIOR (BOX WHEN: v_SUBTFA IS NULL THEN '%' ELSE: v_SUBTFA END)
AND UUT_Part_Number as SUPERIOR (BOX WHEN: v_Part_Number IS NULL THEN '%' ELSE: v_Part_Number END)
AND UUT_Serial_No as SUPERIOR (BOX WHEN: v_Serial_No IS NULL THEN '%' ELSE: v_Serial_No END)
-The next line is for counting WO, given that the WOs repeat the case when count only the last instance of a series of repetitions WO numbers
(CASE WHEN lead (WOs.WONUM, 1, 0) (WOs.wonum order) = WOs.WONUM THEN 0 1 OTHER END);
The error I get is:
ORA-01738: lack of KEYWORD
01738 00000 - "missing IN the keyword"
* Cause:
* Action:
Error on line: 16: 2 column
An indication of error bounces between lines 15 and 16. If I put IN at the end of the 15 I so a missing closing parenthesis error...
Thank you in advance.Pivot operator converts an aggregate table row in a column. The values of distinct line become columns in the output and aggregate column value is placed under the appropriate column Swivel.
The syntax of the Pivot operator is as below:
-- SELECT .. FROM table PIVOT (aggregateFunction [, aggregateFunction] FOR column IN (expression [, expression])) -- WHERE ..
Limitation of the PIVOT operator is, it supports only pivoting on a single column.
You cannot use this:
FOR begin_yr year, AS begin_month IN
See the tutorial several PIVOT columns:
http://mangalpardeshi.blogspot.cz/2009/06/Pivot-multiple-columns.htmland the PIVOT tutorial:
http://www.Oracle-base.com/articles/11g/pivot-and-UNPIVOT-operators-11gr1.php -
Rounding of the aggregate in a PivotTable function
How around the avg (GRADE) when I tried just wrapping around the avg function I get an error message saying to expect the aggregate within the operation of pivot function
Pivot
(avg (GRADE)
for column
in ('1012222', '2221112', 333113');
Thanks for the help.
Edit: Sorry wasn't very clear everything that is shown is the part of pivot of the statement.
Published by: 836321 on February 13, 2011 08:56
Published by: 836321 on February 13, 2011 08:58Hello and welcome to the forum.
It is difficult to see how your piece of pseudo SQL is related to your topic title.
To avoid any problem in their packaging ROUND around AVG:
SQL> select deptno, round(avg(sal)) from emp where deptno in (10,20) group by deptno DEPTNO ROUND(AVG(SAL)) ---------- --------------- 20 2175 10 2917 2 rows selected.
Edit: Sorry, did not only ask bit. You ask no doubt about it:
SELECT * FROM (SELECT deptno, sal FROM emp) PIVOT (ROUND(AVG(sal)) FOR deptno IN (10 AS Accounting, 30 AS Sales)); * Error at line 4 ORA-56902: expect aggregate function inside pivot operation
Suppose you have to (there could be other ways)
SQL> SELECT Round(accounting), round(sales) FROM (SELECT deptno, sal FROM emp) PIVOT (AVG(sal) FOR deptno IN (10 AS Accounting, 30 AS Sales)); ROUND(ACCOUNTING) ROUND(SALES) ----------------- ------------ 2917 1567 1 row selected.
Concerning
PeterPublished by: Peter on February 13, 2011 09:05
Published by: Peter Gjelstrup, February 13, 2011 09:08
-
Smart brains, need help to make SQL -.
This is the simple requirement-
Table X
COLUMN A. COLUMN B
====================
NEW YORK CITY
ETIENNE OF THE CITY
CITY HKG
CITY OF PSC
CITY MOM
FRA CITY
Table Y
COL ATT1 | COL ATT2 | COL ATT3 | COL ATT4 | COL ATT4 | COL ATT5 | COL ATT6 | COL ATT7 | COL ATT8 | COL ATT9 | COL ATT10
=======================================================================================
There are N lines in table X, and values are not known
There are always > table Y N columns and are fixed named
I'm looking for a clever way (database 11g) to formulate an SQL UPDATE to update the table Y with column B of table X - see the output below.
I tried the traditional pivots in pL - SQL, but is not a satisfactory until it.interesting thing here is the number of
lines in the table as x varies.
Table Y
COL ATT1 | COL ATT2 | COL ATT3 | COL ATT4 | COL ATT4 | COL ATT5 | COL ATT6 | COL ATT7 | COL ATT8 | COL ATT9 | COL ATT10
======================================================================================
NYC HNY HGK GSP MOM FRA
Thank you
BobinHi, Blanco,
Blanchy... wrote:
... There are N lines in table X, and values are not knownYou can use the ROW_NUMBER analytic function to assign known values for use in the query.
There are always > N columns in the table Y and are fixed named
I'm looking for a clever way (database 11g) to formulate an SQL UPDATE to update the table Y with column B of table X - see the output below.
I tried the traditional pivots in pL - SQL, but is not a satisfactory until it.interesting thing here is the number of
lines in the table as x varies.What have you tried?
What was unsatisfactory on these methods?
How can we avoid the things you don't like about them if you give some tips on what they were?Here is an example using the Oracle 11 PIVOT function:
WITH got_r_num AS ( SELECT column_b , ROW_NUMBER () OVER (ORDER BY column_b) AS r_num FROM table_x -- WHERE ... ) SELECT * FROM got_r_num PIVOT ( MIN (column_b) FOR r_num IN ( 1 AS att1 , 2 AS att2 , 3 AS att3 -- , ... ) ) ;
It should be easy to write an INSERT statement by using it.
-
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.
-
Support for PIVOT query (or advice on the best way to do it)
Hi gurus of SQL,.
I'd appreciate any help you could provide on this request, I'm assuming that the best way to do this would be by using the PIVOT function. I read through some of the documents and books, and done some research here in the forums, but can't seem to find a way to make it work.
I'm on Oracle 11.1.0.6.0 self.
I have a table like this:
We get this data each month - Month_A is always the most recent month, and so it goes back for this game, Month_A is 09 November, Month_B is October 09, Month_C is Sept 09, etc. I'm OK with Hardcoding this value each month, so for the purposes of this exercise, just assume that Month_A is the 09 November, Month_B is Oct 09, Month_C is Sept 09 and Month_D is Aug 09.ID Product Month_A_Amt Month_B_Amt Month_C_Amt Month_D_Amt 123 ProductA 3 5 7 9 123 ProductB 2 4 6 8 123 ProductC 10 11 12 13 456 ProductA 1 2 3 4 456 ProductB 3 4 5 6
I need essentially "Pivot" in this table, so the end result looks like this:
Here's the SQL code to create the database with test data table. Now that I've typed this explanation, it still seems easier that I had done it to be... but I'm still confused, so any help is greatly appreciated, thank you!ID Month Product_A_Amt Product_B_Amt Product_C_Amt 123 Nov 09 3 2 10 123 Oct 09 5 4 11 123 Sep 09 7 6 12 123 Aug 09 9 8 13 456 Nov 09 1 3 null 456 Oct 09 2 4 null 456 Sep 09 3 5 null 456 Aug 09 4 6 null
create table test_base_table)
Identification number,
Product varchar2 (20).
Number of Month_a_amt
Number of Month_b_amt
Number of Month_c_amt
Number of Month_d_amt);
insert into test_base_table values (123, "ProductA', 3, 5, 7, 9);
insert into test_base_table values (123, "ProductB", 2, 4, 6, 8);
insert into test_base_table values (123, "ProductC", 10, 11, 12, 13);
insert into test_base_table values (456, 'ProductA", 1, 2, 3, 4);
insert into test_base_table values (456, 'ProductB', 3, 4, 5, 6);
Published by: TheBlakester on February 10, 2010 19:56Hello
You don't want to make several clauses UNPIVOT and PIVOT; you want to do several sets of columns in a cluase PIVOT and UNPIVOT one clause.
In the UNPIVOT clause, it's just a matter of replacing the unique "amt" column before the keyword FOR with a list in parentheses '(amt_1, amt_2)' and the replacement of each column in the list (for example, "month_a_amt") with a list of the same length ("(month_a_amt_1, month_a_amt_2)" ").
In the PIVOT clause, it's just a matter of replacing the unique "SUM (amt)" aggregate function with a list of unparenthesized of functions, each with an alias ("the SUM (amt_1) AS amt_1, SUM (amt_2) AS amt_2'. The alias that will be added at the end of the givien for names output column in the IN clause.SELECT id , TO_CHAR ( ADD_MONTHS ( TO_DATE ( 'Nov 2009' , 'Mon YYYY' ) , month_num ) , 'Mon YYYY' ) AS month , product_a_amt_1 , product_a_amt_2 , product_b_amt_1 , product_b_amt_2 , product_c_amt_1 , product_c_amt_2 FROM test_base_table UNPIVOT ( (amt_1, amt_2 ) FOR month_num IN ( (month_a_amt_1, month_a_amt_2) AS 0, (month_b_amt_1, month_b_amt_2) AS -1, (month_c_amt_1, month_c_amt_2) AS -3, (month_d_amt_1, month_d_amt_2) AS -4 ) ) PIVOT ( SUM (amt_1) AS amt_1 , SUM (amt_2) AS amt_2 FOR product IN ( 'ProductA' AS product_a , 'ProductB' AS product_b , 'ProductC' AS product_c ) ) ORDER BY id , month_num DESC ;
Output:
. PRODUCT PRODUCT PRODUCT PRODUCT PRODUCT PRODUCT ID MONTH _A_AMT_1 _A_AMT_2 _B_AMT_1 _B_AMT_2 _C_AMT_1 _C_AMT_2 ---- -------- -------- -------- -------- -------- -------- -------- 123 Nov 2009 3 9 2 9 10 9 123 Oct 2009 5 9 4 9 11 9 123 Aug 2009 7 9 6 9 12 9 123 Jul 2009 9 9 8 9 13 9 456 Nov 2009 1 9 3 9 456 Oct 2009 2 9 4 9 456 Aug 2009 3 9 5 9 456 Jul 2009 4 9 6 9
It looks like all the new values of amt2 are 9. Don't you think it's the best test? I think that different numbers, as you used for the examples of previous data, reduce the chances of getting good results purely by chance.
If you want to experiment with queries like this, I suggest you use "SELECT *" (nothing added) in the SELECT clause. Start with just an UNPIVOT operation. Some examples in the documentation to do a TABLE CREATION AS... to save the results of an UNPIVOT operator and use this table as the base for a PIVOT table. I think it's a good idea to reduce confusion.
-
Requesting help with pivot in Oracle 10 g
Hey all,.
I have this table, call the table GRID that has the following columns:
What would take to rotate the names of column ("M1100", "M1105") with the value metric volumn: "COMMITTEDVIRTUALMEMORYSIZE_AVG", so that this query would yield a result like this:OBJECT_KEY DATE_KEY SEGMENT_ID COLUMN_NAME COMMITTEDVIRTUALMEMORYSIZE_AVG ---------------------- ---------------------- ---------------------- ----------- ------------------------------ 619 3371 1 M1100 593589862.4 619 3371 1 M1105 593611434.67 620 3371 1 M1100 592354508.8 620 3371 1 M1105 592376263.11 621 3371 1 M1100 731433369.6 621 3371 1 M1105 731455943.11
Any help would be appreciated!OBJECT_KEY DATE_KEY SEGMENT_ID M1100 M1105 ---------------------- ---------------------- ---------------------- ----- ------ 619 3371 1 593589862.4 593611434.67 620 3371 1 592354508.8 592376263.11 621 3371 1 731433369.6 731455943.11
Again, Oracle 10 g, 11g not so I don't have the PIVOT function to work with.
Kind regards
TimS
Maybe you are looking for
-
It seems to me that the only thing that a lot of the so-called personal motorcycle, experts, managers what ever here are much less locks threads when everything becomes hot or hard for them to answer/handle whatever. Take this position all the time,
-
Computer came with McAfee SafeLife - Internet Security pre-installed. I would like to know if Windows Defender and Windows Firewall that came with the computer, but not installed would be the way to go since the McAfee free trial version is about to
-
Get the value of crete only 1 per cycle
Hello I am a student in island and my subject transit on a plate to 2.2 Hz for 30 seconds. I try produce a reaction force of ground spike for each section in a bar chart, but my short program so fast that I get multiple peaks for each section (see at
-
"COM Surrogate has stopped working"
OP: COM SurrogateHow can I get laughs at the pop up message "COM Surrogate has stopped working '? What is it??? How should I do?
-
I have now ASA5506 with the service of firepower can detect phishing Web sites, block ads on Web sites and detect any harmful cookies or male-ware on the websites and what licensing requirements.