Pivot a table
Hi All,
I have this query:
select columnA, columnB
,sum (Case when wType='FULL' then YEAR_1 else 0 end) as FULL_1
,sum (Case when wType='FULL' then YEAR_2 else 0 end) as FULL_2
,sum (Case when wType='PART' then YEAR_1 else 0 end) as PART_1
,sum (Case when wType='PART' then YEAR_2 else 0 end) as PART_2
from (
select * from qryA
union all
select * from qryB
group by columnA, columnB, wType
order by columnB
I am using Coldfusion and i cannot use "case" statement or "with" in query of queries.
How can I do the same without using case or with?
Thanks
Hi,
WITH clauses have been part of Oracle since 2001, CASE expressions have been in Oracle since 1998, and DECODE since at least 1988. That's probably older than some of the people working at your firm. You may want to re-consider why you are using sortware that keeps you so far out of date.
If you really do need to use software like that, you can hide the "new" features in a view. For example, if you're using Oracel 11.1 or higher, you could have a view that includes SELECT ... PIVOT, but all your front end needs to see is SELECT * FROM my_view.
Does Cold Fusion have its own way of pivoting?
Similar Messages
-
Hi i am new to OAF. Please someone help me in how to create a Pivot report table in OAF?
The table structure should be like
_______________________________________Column1________________________Column2____________________Column3
_______________________________________Part1 __________________________ Part2______________________Part3
_______________________________________Part 1.a_____Part1.b____________ Part2.a_______ part2.b_________Part3.a_______ part3.c
Row1__Organization name1 Manager Name1 count of employees
Row2__Organization name2 Manager Name2 count of employees
Edited by: 847828 on Mar 28, 2011 1:27 AM
Edited by: 847828 on Mar 28, 2011 1:33 AM
Edited by: 847828 on Mar 28, 2011 1:39 AMHi,
Kindly elaborate your requirement.
Thanks,
Gaurav -
Hi,
Need help in pivot the table.
Table data
NAME
LINE_TYPE_REF_ID
Class
CreateShipmentServiceAdapterImpl
Method
getContactsAndSitesForAccount
User
skkond
Node Name
PB15CKY
Num Contacts
3
Class
CreateShipmentServiceAdapterImpl
Method
getContactsAndSitesForAccount
User
drcoul
Node Name
C4F6JJ1
Num Contacts
21
Class
CreateShipmentServiceAdapterImpl
Method
getContactsAndSitesForAccount
User
drcoul
Node Name
C4F6JJ1
Num Contacts
21
Required
Class
Method
Node Name
Num Contacts
User
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
PB15CKY
3
skkond
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
C4F6JJ1
21
drcoul
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
C4F6JJ1
21
drcoul
Thanks,
Tiru.Using PIVOT function ( for versions >= 11g ):
with table_x as
select 'class' name, 'CreateShipmentServiceAdapterImpl' rid from dual UNION ALL
select 'method' name, 'getContactsAndSitesForAccount' rid from dual UNION ALL
select 'user' name, 'skkond' rid from dual UNION ALL
select 'node_name' name, 'PB15CKY' rid from dual UNION ALL
select 'num' name, '3' rid from dual
UNION ALL
select 'class' name, 'CreateShipmentServiceAdapterImpl' rid from dual UNION ALL
select 'method' name, 'getContactsAndSitesForAccount' rid from dual UNION ALL
select 'user' name, 'drcoul' rid from dual UNION ALL
select 'node_name' name, 'C4F6JJ1' rid from dual UNION ALL
select 'num' name, '21' rid from dual
UNION ALL
select 'class' name, 'CreateShipmentServiceAdapterImpl' rid from dual UNION ALL
select 'method' name, 'getContactsAndSitesForAccount' rid from dual UNION ALL
select 'user' name, 'drcoul' rid from dual UNION ALL
select 'node_name' name, 'C4F6JJ1' rid from dual UNION ALL
select 'num' name, '21' rid from dual
---- Sample data ends here
SELECT * FROM (select
Trunc((ROWNUM-1)/5) id, name, rid
from table_x)
PIVOT(
MIN(rid)
FOR
name IN ('class','method','user','node_name','num')
ORDER BY id;
OUTPUT :
ID
'class'
'method'
'user'
'node_name'
'num'
0
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
skkond
PB15CKY
3
1
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
drcoul
C4F6JJ1
21
2
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
drcoul
C4F6JJ1
21
The Trunc((ROWNUM-1)/5) is added as an ID column... This has a very important role to play.
ROWNUM values = {1, 2, 3, 4, ... n}
where
n = total no of rows fetched by the query
Division-by-5
Since there are 5 column (in this scenario), so we need to group each set of 5 consecutive rows.
So, Group-1 : rows {1,2,3,4,5} , Group-2 : rows {6,7,8,9,10} and so on...
Now, if you Divide each value by 5 and then do TRUNC, you'll get an Id (or say "Group-id") with each group of 5 consecutive rows.
This so-called "Group-id" generated will help to do a GROUP BY operation which is mandatory for the Aggregate operation in PIVOT function.
Hope that helps,
-- Ranit -
How to setup DRILL/PIVOT in table region :
plzz tell me how to setup DRILL/PIVOT in table region in Oracle Daily Business Intelligence Dashboard.
what is the setting? to show drill/pivot option in table region [first column]Hi Sai Krishna,
There is a very small difference between these two when you will create dependent LOV in Table or Advanced table the all the FormValue items to store ids which will be used as crieteria map or return items should be created inside table/Advanced table region.
Hope this will help.
Regards,
Reetesh Sharma -
Error while importing text file to Power Pivot via Table Import Wizard
Hello there,
I'm a rookie at handling Excel to be honest. I've been trying to import a .txt file to Excel (it contains around 14 million rows of information) but Excel won't let me since it can only handle around 1 million rows per sheet (too troublesome to do such thing
14 times in 14 different sheets). Then I googled that Power Pivot let me handle around 100 million rows in a Pivot.
I'm trying to import this .txt file to Power Pivot by doing the following:
Home tab > From Text > File Path (insert .txt location here) > Finish
After that it shows the Table Import Wizard retrieving the rows from the .txt file. Problem is... at the end of the import (once it hits row 14,000,000 or so) it shows an error. It states the following:
"Memory error: Allocation failure : Not enough storage is available to process this command. .
The current operation was cancelled because another operation in the transaction failed."
Please note that the size of the .txt file is 900 MB.
Another thing is that, when I select the .txt file from its location at the File Path section, the "preview" field only shows 50 rows, not all of them. Is that okay to happen?
Is it because the size of the .txt file is too big?
Please let me know if you need more info in regards to this.
Thanks in advance.Hi AdiUser,
Only showing 50 rows for the preview is normal behaviour. Based on what you've described, it sounds like Power Pivot is running out of memory when you are loading this .txt file. Are you running the 32 bit or 64 bit version of Excel. Also, if you are running
the 64 bit version how much RAM is available?
If you're running the 32 bit version then the available RAM for Power Pivot is less than 1 GB even if the system has more than this installed. You can address this by installing the 64 bit version. If you're running the 64 bit version then it may be
that you don't have enough RAM to accommodate this amount of data and you may consider upgrading the RAM. Alternatively, you could try and reduce the size of the table in memory by using the preview screen to remove any columns that are not of use. This
is especially important if there are any column with a high number of unique values that aren't actually needed in the model. In addition to removing columns altogether, you could try filtering the data so that only a subset of the rows are imported.
This can also be done from the preview screen.
Regards,
Michael Amadi
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)
Website: http://www.nimblelearn.com
Blog: http://www.nimblelearn.com/blog
Twitter: @nimblelearn -
Dear All,
Here is my Thread..
I have a one table [ABC] with Column Name [YEAR_MONTH], [RECORD_ID],[SALE],[MANAGER]
The Distinct [MANAGER]s are - [AAA],[BBB],[CCC] & [DDD]
I want to pivot a report from TABLE in this way..
Please help..In T-SQL it can be done as follows
SELECT YEAR_MONTH,
COUNT(CASE WHEN MANAGER = 'AAA' THEN RECORD_ID END) AS [MANAGER1COUNT],
SUM(CASE WHEN MANAGER = 'AAA' THEN SALE END) AS [MANAGER1SUM],
COUNT(CASE WHEN MANAGER = 'BBB' THEN RECORD_ID END) AS [MANAGER2COUNT],
COUNT(CASE WHEN MANAGER = 'BBB' THEN SALE END) AS [MANAGER2SUM],
COUNT(CASE WHEN MANAGER = 'CCC' THEN RECORD_ID END) AS [MANAGER3COUNT],
SUM(CASE WHEN MANAGER = 'CCC' THEN SALE END) AS [MANAGER3SUM],
COUNT(CASE WHEN MANAGER = 'DDD' THEN RECORD_ID END) AS [MANAGER4COUNT],
SUM(CASE WHEN MANAGER = 'DDD' THEN SALE END) AS [MANAGER4SUM]
FROM Table
GROUP BY YEAR_MONTH
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Default Max rows for pivot and table view that can display
Hi Experts,
what was the Maximum number of pivot table records,Maximum number of pivot table populated cells,Maximum number of table view rows by default in OBIEE.
If i want to see where i can found all these things in OBIEE.
If i want to change the default range of these rows is there any maximum limit for setting manually also or we can set any number of records.(i.e. if i want to display 100000 records will accept or there will be any range for setting also)
Thanks,
Edited by: RAJ.bi on Aug 5, 2012 8:12 AMCheck the below link for the same
http://docs.oracle.com/cd/E25178_01/bi.1111/e10541/answersconfigset.htm
If you are going with 100K records per view, I think there is a limit for downloading into spread sheet.
Pls mark correct or helpful -
How to 'pivot' a table without aggregating the data?
Hi!
Suppose I have a simple query which returns the 1st (yellow) table in the attached picture.
I wish to convert this table to the 2nd table (green). This is sort of a pivoted table, but all the individual rows are shown separately, and not aggregated
How can this be done?
The simple query could be as follows:
CREATE TABLE #Table1
(Type varchar (10),
DocNum Int,Qty Int)
Insert into #Table1 Values
('SOrder', '1125','100'),
('POrder','4615','50'),
('POrder','4616','50'),
('GRPO','2001','25'),
('GRPO','2002','25'),
('GRPO','2003','25')
SELECT * FROM #Table1
Note: In the "transposed" table, the rows can be in any order
Thanks
Leon LaiHi Visakh,
Thanks a lot for your reply.
It works fine for me, and your query gave the foll. results which are exactly what I wanted:
Sorder_Type
SOrder_DocNum
Porder_Type
POrder_DocNum
GRPO_Type
GRPO_DocNum
SOrder
1125
POrder
4615
GRPO
2001
NULL
NULL
POrder
4616
GRPO
2002
NULL
NULL
NULL
NULL
GRPO
2003
I cant understand reason behind requirement like this
It is rather difficult to explain my rationale in this forum.
In brief, I am developing a kind of relationship map for all documents in a chain of transactions.
I would need to trace all base documents and all target documents in the chain, but the relationships
can be extremely complex in real life. So, I chose to ignore all the exact joins, and to simply list the relevant documents in any
order.
It is quite remarkable that you have correctly answered my question, even though you could not understand my rationale.
Best Regards
Leon -
Problem with the Pivote Table order by Clause in OBIEE report
Hello All,
Can anyone help?
I am developing a report with 3 columns
1. Year
2. Customer name
3. Amount
I need Year in Ascending & Amount Descending (Group by Year and then Desc by amount)
In Table view data is displayed correctly, but in Pivote Table it’s not sorting correctly
Table View ( This is correct)
Year Customer Name Amount
2009, a1, 260,000.00
a2, 152,030.00
a3, 20,000.00
2008, a6, 193,080.00
2004, a7, 860.2
a8, 114.7
2003, a9, 200,243,813.40
a10, 91,351,364.10
Pivote Table Results as follows:
Year Customer Name Amount
2009, a1, 260,000.00
a2, 152,030.00
a3, 20,000.00
2008, a6, 193,080.00
2004, a7, 860.2
a8, 114.7
2003, x, 26,374,818.00
y, ....................
a9, 200,243,813.40
For year 2003 in place of 'x' value a9 value has to be shown........
Regards,
SMAYour post doesn't help a lot. Why it's still not solved ?
If it's caused by the ascendant order, the only way that you have is to pivot your table :
http://gerardnico.com/wiki/dat/obiee/presentation_service/obiee_transformation_table_to_pivot
And then you can set all sort that you want.
success
Nico -
Measure Values are not shown in the pivot tables
Measures without aggregation (in rpd) are not shown in pivot table.
Im trying to add multiple columns in the fact table as measures,one which is summable had has the SUM function and three which are not summable.
The initial report will be as follows and I have been able to get the data displayed.
Year | Month| Company Name| SUM(C1)| C2|C3
However if I pivot the table as follows data in column C2 and C3 are not Displayed.
Columns
Year
Month
Company
Rows
Measure Lablel
Measures
SUM(C1)
C2
C3
Should we have an aggregation rule applued in C2 and C3 ?Yes, all the column entries must have agg rule. You can specify one such as 'first' in the pivot table.
-
Pivot Table with Dynamic Columns and Headers
Hello,
I'm trying to pivot a table of data where the column headers will be dynamic. While I know how to pivot the table to get what I want how will I be able to pick up the table column header from the Pivot to display in the report?
For example:
Unpivoted data is Employee Code, Branch Code, Problem Code, # of Problems.
There is many records for a given Employee and Branch that I want to pivot so the Column headers are the Problem Codes and the data below is the SUM(num_problems) for that Problem.
So the data may look like this for Tech Bob, Branch NY.
Problem = LEAK, Num_problem = 5
Problem = DAMAGE, Num_problem = 2
Problem = OTHER, Num_problem = 3
Which problem codes may appear is unknown but selecting the DISTINCT(problem) across all techs gives me the column headings to use.
So if I pivot this data, I get this Row:
Tech = Bob, Branch = NY, DAMAGE = 2, LEAK = 5, OTHER = 3
So first can SSRS handle having dynamic columns? Only Tech and Branch are known and the remaining columns are dynamic based on how many Problems they worked on.
Second, how can I set the column heading in my Tablix to be the Problem Code?
SherryYou just need to use a matrix container
Use EmployeeCode and BranchCode for row group
ProblemCode as column group and SUM([No Of Problems]) as the data expression and it will generate the columns for you based on ProblemCode values automatically.
See an example here
Sample Matrix
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
I try to find such as pivot table like in excel sheet
How to collect data like pivot table in excel sheet. Please help me
Hi Chepot,
Welcome to Apple Discussions and the Numbers '09 forum.
Numbers does not support pivot tables, but there may be a way to accomplish what you want.
Here's a link to search results for 'pivot AND table' in the Numbers '09 forum during the past year. Check these prior discussions. If they don't answer your question, post a reply here with further details on the arrangement of data you want to collect.
Regards,
Barry -
create table mytable
name varchar2(50),
surname varchar2(50)
insert table mytable values('mary','john')
insert table mytable values('mary','baby')
insert table mytable values('mary','lady')
insert table mytable values('sean','kate')
insert table mytable values('sean','terry')
insert table mytable values('kate','tom')
insert table mytable values('kate','lary')
my query result is
name surname
mary john
mary baby
mary lady
sean kate
sean terry
kate tom
kate lary
i want like this
mary sean kate
john kate tom
baby terry lary
lady
this is not the all data.
the data is changable.there are 3 name like john 2 name like sean 2 name lik kate and there will be 5 name like paul....i want name like column and surname like data..
thanks for your helps....Hi,
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 isn't quite what you requested:
. R_NUM MARY SEAN KATE
1 baby kate lary
2 jon terry tom
3 ladyYou don't have to display r_num: I showed it just to make things easier to understand.
If the output should really include 'john' rather than 'jon', and/or if it needs to appear above 'baby' rather than below it, then please explain.
If the names in the columns ('mary', 'sean' and 'kate' in your sample data) need to be determined at run-time, then you need dynamic SQL to generate a statement like the one above.
The script below shows one way of doing that in SQL*Plus.
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.
*/ -
Crosstabs or Pivot table using oracle 11g
Hi All,
I want to pivot my table and create something like below:
I have table in this format
Output Detail Objective Measure
NVM CSV Some text some text
VS F&M Some text somet text
I want it to display like on page
Output: NVM
Detail: CSV
Objective: Some text
Measure: some text
Output: Vs
Detail:CSV
Objective: Some text
Measure: Some text
Any idea how to do it?
Thanks in advancePivot does not appear to be necessary. Create a standard report using one of the default: vertical report... built-in report templates, or the Value Attribute Pairs template from the current theme.
(Please update your forum profile with a real handle instead of "858002".) -
Pivoting table results so YearIDs become columns with all other data underneath them
The table above has all the data I need for my report, however, I need to pivot the table so that each YearID (based upon corresponding fkYear) is a separate column and the rest of the data in each row appears under the appropriate Year ID. I'm trying
to pivot the table but I'm stuck on exactly how to do it.
RandyHJ1957Ok, here is what I have so far as a PIVOT using a CTE
WITH ActiveAccountCodes AS
SELECT BWfkYear, BWYearID, BWFund, BWMajorObject, BWObject, BWObjectDescr, BWAmount, BWDescr FROM @TmpProposedAccountCodes
UNION
SELECT BWfkYear, BWYearID, BWFund, BWMajorObject, BWObject, BWObjectDescr, BWAmount, BWDescr FROM @TmpCurrentAccountCodes
UNION
SELECT BWfkYear, BWYearID, BWFund, BWMajorObject, BWObject, BWObjectDescr, BWAmount, BWDescr FROM @TmpBudget1AccountCodes
UNION
SELECT BWfkYear, BWYearID, BWFund, BWMajorObject, BWObject, BWObjectDescr, BWAmount, BWDescr FROM @TmpBudget2AccountCodes
UNION
SELECT BWfkYear, BWYearID, BWFund, BWMajorObject, BWObject, BWObjectDescr, BWAmount, BWDescr FROM @TmpBudget3AccountCodes
SELECT BWObject, BWObjectDescr, Proposed, Current, Actual1, Actual2, Actual3, BWDescr
FROM ActiveAccountCodes
PIVOT(SUM(BWAmount) FOR BWYearID IN ([SELECT BWYearID FROM @TmpProposedAccountCodes AS [Proposed]], [SELECT BWYearID FROM @TmpCurrentAccountCodes AS [Current]],
[SELECT BWYearID FROM @TmpBudget1AccountCodes AS Actual1],
[SELECT BWYearID FROM @TmpBudget2AccountCodes AS Actual2],
[SELECT BWYearID FROM @TmpBudget3AccountCodes AS Actual3] )) AS PVT
The error I am getting now is where I attempt to define the Proposed and Current column headings using a select statement to get the right YearID for the right year. I get a red line under Proposed and Current in the main query above the PIVOT expression
RandyHJ1957
Maybe you are looking for
-
Song no longer available for purchse error
I tried on Monday to purchase two songs but got an error saying that they were no longer available for purchase, even though a can listen to the preview. I click OK to the error prompt and thought no more of it. I recently check my back account and I
-
CS4 document in CS5: Text is underlayed yellow
Hi, when opening a CS4 document in CS5, some text is now underlayed yellow. Strangely, almost always just headings and not all words or even letters. Can anyone tell me what this means and which settings are responsible for this? Thanks!
-
I have tried to open Itunes and am getting the message "this copy of I Tunes is corrupted or is installed correctly". Any idea what I should do? had just updated the spftwear throtuh the site on my Ipad but it seems to be working ok?
-
Setting up a "Dual Boot" system by adding Lion to an external HD
I had originally thought to put my present Snow Leopard with Parallels OS's on an external HD the upgrading my internal HD to Lion in order to retain my Classic Application (AppleWorks in particular) capability for access to about a thousand old Appl
-
Is there a way to merge two libraries ? On my MBPro I have one iTunes library. On my MacPro another. There's some cross over of music, but a lot of difference too between them. Can I merge the two library files (on my external terabyte drive) and imp