Crosstab Query?
Is there Oracle Crosstab query like access?
Hi,
Shirani wrote:
... Any idea to diplay data in this format using ASP Classic Code.. but connectivity with Oracle DB?Sorry, I don't know anything about ASP.
If the problem is that ASP needs to know how many columns the dynamic query will be returning, then perhaps you can do something on the ASP side like the preliminary query.
Another approach would be not to return separate columns, but to concatenate the pivoted results into one huge VARCHAR2 column, with the columns delimied as in a csv file. This might be simpler on the Oracle side; you can do String Aggregation without dynamic SQL. Your ASP application could then parse the huge VARCHAR2 to get the individual parts.
Similar Messages
-
Dear members:
I have been trying to generate a crosstab query in Oracle using SQL.
This is the situation:
I have two tables in Oracle. One contains characteristics of institutions which people visit, and includes, amongst other fields, the ID of the institution (number) and an identificator for the district where the institution is implanted (number; ranging 1 - 18).
The second table also contains a field with the ID of the institution, and more: the date when the visit occured (date), and a sequential (unique) number for each visit.
What I need to obtain is a final table containing the following fields:
Date of the visit, total number of visitors per date of visit, and a field for each district containing the total number of visitors to instituitions of the district per each date of visit.
Can anyone give me a hint on this?
Also; is there a user-frindly interface minimizing the use of SQL that I can download from Oracle for generating this?
Thank You
AndréCrosstab is a reporting function not a SQL one. SQL statements must have a fixed number of columns regardless of the data.
The only way to do it using SQL is to use PL/SQL to generate a dynamic query as shown on Ask Tom here
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:15151874723724
Otherwise there are reporting tools such as Oracle Reports that can do it as well. -
Format Column Header in Crosstab Query in Crystal Reports for Enterprise
Hi
I am using Crystal reports for Enterprise and I would like to format the Column header of a crosstab query one block of colour say light blue. However I cannot select the header in isolation to the rest of the cross tab. All I can select is either column text boxes, which doesnu2019t look good formatted as a different colour to the background of the crosstab. Or I can only select either entire column or the entire row, which kind of defeats the object of formatting just the column header itself. Is there a way to isolate the column headers so I can format just the header, as the report is looking extremely bland all in white?
Many Thanks in advance
Regards
NeilAlright, here's what you need to do:
1) RIght-click one of the Column Headers and select 'Format Result Object Element' > Appearance > click on the formula button (fx) beside 'Fill' and use this code:
if currentrowindex < 0 then crBlue
You wanted light blue right? So, the rgb value for light blue or sky blue would be 135-206-250. So, you can change the color by modifying the formula like this:
if currentrowindex < 0 then color(135,206,250)
If this is not the exact blue you're after, just google!
Hope this helps!
-Abhilash -
Custom column in Crosstab query in BO 6.5
Hello Gurus,
I am trying to create a report in BO 6.5 using data from two flat files by linking them and I applied cross-tab template as I need row data as columns based on a field called STATUS (Approved, Cancelled, In process etc). And in this STATUS field I want to add another column (Not Ordered) on the run using some conditions which is not in the flatfile. How can I do that?
Please let me know if my post in unclear so that I can provide more data regarding the report.
Thanks in advance for your time.Let me elaborate my requirement. I am trying to create a report using data from two flat files. I am supposed to give the status of orders. So I created crosstab query and I chose STATUS field data to be as columns. Currently it have three fields----Approved, In process, Waiting for approval. Now as per requirement I am supposed to include another column called Not applicable based on two fields Amount and Local/No local. Before this we used to create the same report uising excel and I used below formula:
=IF(AND(Amount=0,B2="Non-Local"),"Not Applicable","Approved")
But in BO if the above condition is False I want that particular record to fall under already existing "Approved" but it is creating another "Approved" status and it is not catagorizing Not applicable....I mean every record with amount =0 falls under new Approved status but not in Not applicable as expected. Hope you understand my issue.
Am i doing anything wrong in creating formula? -
Display Crosstab query in DataGrid
Hi, I'm a Flex beginner. Could someone please help me how to
display crosstab query result in DataGrid? The following query
returns 6 columns:
- First column: values in the field Sell_Channel
- Second: Sum(Revenue Total) from the Revenue field.
- Others: Revenue Subtotal by Sell_Channel and quarter.
Quarters are values stored in the field name Quarter. In Datagrid,
what would be the datafield for these 4 quarter columns?
Thanks millions.
Here is my SQL:
TRANSFORM Sum(Revenue.RevenueTotal) AS SumOfRevenueTotal
SELECT Revenue.Sell_Channel, Sum(Revenue.RevenueTotal) AS
[Total Of RevenueTotal]
FROM Quarter INNER JOIN Revenue ON Quarter.FiscalQuarter =
Revenue.Quarter
WHERE (Revenue.Fiscal_Year="2006")
GROUP BY Revenue.Sell_Channel
PIVOT Quarter.Quarter;Crosstab is a reporting function not a SQL one. SQL statements must have a fixed number of columns regardless of the data.
The only way to do it using SQL is to use PL/SQL to generate a dynamic query as shown on Ask Tom here
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:15151874723724
Otherwise there are reporting tools such as Oracle Reports that can do it as well. -
Use for a Crosstab Query?
I have a table with the following metric data in it.
one entry for a metric, whether its integrity was checked and the date checked.
I need a report that puts all monthly activity on a single line.
Examples:
Here's what the table looks like
proj_name metric integrity_checked Date
abc broke Y 01-Apr-08
abc fixed Y 01-Apr-08
abc trashed Y 01-Apr-08
abc broke Y 01-Mar-08
abc fixed Y 01-Mar-08
abc trashed Y 01-Mar-08
xyz broke Y 01-Apr-08
yxz fixed Y 01-Apr-08
yxz trashed Y 01-Apr-08
yxz broke Y 01-Mar-08
yxz fixed Y 01-Mar-08
yxz trashed Y 01-Mar-08
Report needs to look like this.
Prog Metric Apr-08 Mar-08
abc broke Y Y
abc fixed Y Y
abc trashed Y Y
xyx broke Y Y
xyz fixed Y Y
xyz trashed Y Y
Does this call for a crosstab-type query and if so
how would I code it?
I've done one crosstab query before but can't get this one to come out right.
Thanks
DavidSee this link
http://www.myoracleguide.com/s/Pivot_Tables.htm -
Crosstab Query for Remaining Revenue (Count, If, Date Between )
Hi all, hope you had a great new year.
I am wanting to create a crosstab query for my Projects which shows ProjectID in the row headers and Time Periods split into months quarter or year as the Column Headers using the [DateAgreed] from the Session table.
I have created crosstabs which show revenue from sessions and count of sessions with different time periods but i am trying to make it so that it counts only completed sessions from before the column date, so that i can then multiply by the [SessionCost].
Any ideas guys?
Here's what i have been working with;
TRANSFORM Sum(([tblSession]![SessionCompleted]*[tblProject]![SessionCost])) AS Revenue
SELECT tblProject.ProjectID, tblCompany.CompanyName
FROM (tblSession INNER JOIN tblCompany ON tblSession.CompanyID = tblCompany.CompanyID) INNER JOIN ((tblProject INNER JOIN tblProjectMetrics ON tblProject.ProjectID = tblProjectMetrics.ProjectID) INNER JOIN qryProjectStatus ON tblProject.ProjectID = qryProjectStatus.ProjectID)
ON (tblProject.ProjectID = tblSession.ProjectID) AND (tblCompany.CompanyID = tblProject.CompanyID)
GROUP BY tblProject.ProjectID, tblCompany.CompanyName, tblProject.Total
PIVOT Format([DateAgreed],"yyyy-mm");
Thanks :)Hi Gord0oo,
You could concatenates the data as a result and show in a cell.
TRANSFORM Sum([tblProject]![SessionCost])) & ";" & Sum([tblSession]![SessionCompleted]) AS Revenue
Regards
Starain
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Is it possible to do perform data entry in a crosstab query view?
If you want to insert, update or delete in a view you need to write ON-INSERT, ON-UPDATE and/or ON-DELETE trigger and perform your DML inside these triggers ...
Hope it helps
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by JAMIE MCPHIE ([email protected]):
Is it possible to do perform data entry in a crosstab query view?<HR></BLOCKQUOTE>
null -
Crosstab query is it possible in BEX?
Hi
I am working with the Marketing attributes ODS 0ATR_DS01 and I want a query that has the partner in rows with the attribute name in columns showing the attribute values i.e. a crosstab query.
I've been playing with BEx trying to create a crosstab query - something I thought should be very straight forward but I just don't seem to be able to get it to work. I searched the forums for Crosstab and don't get any hits, has anyone tried to create a crosstab - is it possible with BW - if so please point me in the right direction.
Regards
GarethHi,
Make the<i> Attribute</i> the navigational attribute.
Then you can take Partner in rows and <i>attribute</i> in columns.
With rgds,
Anil Kumar Sharma .P -
Hi
I'd like to create a crosstab query but I'm not sure what function to use to do it.
MSAccess has 'Transform' but what do I use in Oracle SQL?
Does anyone have any examples or references to look at? ThanksWoof,
Here's an example. If you are running Oracle 11, then Pivot is also available.
SELECT state,
round( sum( mens ), 2 ) "Mens",
round( sum( womens ), 0 ) "Womens",
round( sum( accessories ), 0 ) "Accessories"
FROM ( SELECT demo_customers.cust_state state,
CASE
WHEN demo_product_info.category = 'Mens'
THEN
demo_order_items.quantity * demo_order_items.unit_price
ELSE
0
END
mens,
CASE
WHEN demo_product_info.category = 'Womens'
THEN
demo_order_items.quantity * demo_order_items.unit_price
ELSE
0
END
womens,
CASE
WHEN demo_product_info.category = 'Accessories'
THEN
demo_order_items.quantity * demo_order_items.unit_price
ELSE
0
END
accessories
FROM demo_order_items,
demo_product_info,
demo_customers,
demo_orders
WHERE demo_order_items.product_id = demo_product_info.product_id
AND demo_order_items.order_id = demo_orders.order_id
AND demo_orders.customer_id = demo_customers.customer_id )
GROUP BY ROLLUP( state )Jeff -
Crosstab query using pure SQL only
Hi all,
Found a lot of threads on crosstab, but none seems to address what I need. I need to perform crosstab query using pure SQL only & the number of columns are dynamic. From a query, I obtained the below table:
Name Date Amount
Alex 2005-06-10 1000
Alex 2005-06-20 1000
Alex 2005-07-10 1000
Alex 2005-07-20 1000
Alex 2005-08-10 1000
Alex 2005-08-20 1000
John 2005-06-10 2000
John 2005-06-20 2000
John 2005-07-10 2000
John 2005-07-20 2000
John 2005-08-10 2000
John 2005-08-20 2000
And I need to transform it into:
Name 06-2005 07-2005 08-2005
Alex 2000 2000 2000
John 4000 4000 4000
Reason for the columns being dynamic is because they'll be a limit on the date ranges to select the data from. I'd have a lower & upper bound date say June-2005 to August-2005, which explains how I got the data from the above table.
Please advise.
Thanks!Hi,
I couldn't resist the intellectual challenge of a pure SQL solution for a pivot table with a dynamic number of columns. As Laurent pointed out, a SQL query can only have a fixed number of columns. You can fake a dynamic number of columns, though, by selecting a single column containing data at fixed positions.
<br>
<br>
If it were me, I'd use a PL/SQL solution, but if you must have a pure SQL solution, here is an admittedly gruesome one. It shows the sum of all EMP salaries per department over a date range defined by start and end date parameters (which I've hardcoded for simplicity). Perhaps some of the techniques demonstrated may help you in your situation.
<br>
<br>
set echo off
set heading on
set linesize 100
<br>
select version from v$instance ;
<br>
set heading off
<br>
column sort_order noprint
column sal_sums format a80
<br>
select -- header row
1 as sort_order,
'DEPTNO' as DEPTNO ,
sys_connect_by_path
( rpad
( to_char(month_column),
10
' | '
) as sal_sums
from
select
add_months( first_month, level - 1 ) as month_column
from
( select
date '1981-01-01' as first_month,
date '1981-03-01' as last_month,
months_between( date '1981-03-01', date '1981-01-01' ) + 1 total_months
from dual
connect by level < total_months + 1
) months
where
connect_by_isleaf = 1
connect by
month_column = add_months( prior month_column, 1 )
start with
month_column = date '1981-01-01'
union all
select -- data rows
2 as sort_order,
deptno,
sys_connect_by_path( sum_sal, ' | ' ) sal_sums
from
select
dept_months.deptno,
dept_months.month_column,
rpad( to_char( nvl( sum( emp.sal ), 0 ) ), 10 ) sum_sal
from
select
dept.deptno,
reporting_months.month_column
from
dept,
( select
add_months( first_month, level - 1 ) as month_column
from
( select
date '1981-01-01' as first_month,
date '1981-03-01' as last_month,
months_between( date '1981-03-01', date '1981-01-01' ) + 1 total_months
from
dual
connect by level < total_months + 1
) reporting_months
) dept_months,
emp
where
dept_months.deptno = emp.deptno (+) and
dept_months.month_column = trunc( emp.hiredate (+), 'MONTH' )
group by
dept_months.deptno,
dept_months.month_column
) dept_months_sal
where
month_column = date '1981-03-01'
connect by
deptno = prior deptno and
month_column = add_months( prior month_column, 1 )
start with
month_column = date '1981-01-01'
order by
1, 2
<br>
VERSION
10.1.0.3.0
<br>
DEPTNO | 81-01-01 | 81-02-01 | 81-03-01
10 | 0 | 0 | 0
20 | 0 | 0 | 0
30 | 0 | 2850 | 0
40 | 0 | 0 | 0
<br>
Now, if we substitute '1981-03-01' with '1981-06-01', we see 7 columns instead of 4
<br>
DEPTNO | 81-01-01 | 81-02-01 | 81-03-01 | 81-04-01 | 81-05-01 | 81-06-01
10 | 0 | 0 | 0 | 0 | 0 | 2450
20 | 0 | 0 | 0 | 2975 | 0 | 0
30 | 0 | 2850 | 0 | 0 | 2850 | 0
40 | 0 | 0 | 0 | 0 | 0 | 0
<br>To understand the solution, start by running the innermost subquery by itself and then work your way outward. -
I've created the below crosstab query for a report.
Select Grouping_Condition,Warehouse,Max(Value) Over (Partition By Grouping_Condition,Warehouse) As Total,
Sum(Value) Over (Partition By Warehouse) As Total_Containers_Per_Warehouse,
Sum(Vat1Ue) Over () As Total_Containers,
(Max(Vat1Ue) Over (Partition By Grouping_Condition,Warehouse))
/(Sum(Vat1Ue) Over (Partition By Warehouse))*100 As Total_Pct
From
Seleect Grouping_Condition,Warehouse,Count(*) As Value
From
Set1Ect
T1.Warehouse,Shipped_Weight As Shipped_Tons,T1.Max_Weight As Maxtonnes,
Case When (Shipped_Weight)< (T1.Max_Weight*0.001)*0.95 Then 'containers_under_95'
When (Shipped_Weight*0.001) Between (T1.Max_Weight*0.001)*0.95 And (T1.Max_Weight*0.001) Then 'containers_95_100'
Et1Se 'containers_above_weight'
End Grouping_Condition
From
Tabt1E1 T1
,Tabt1E2 T2
,Tabt1E3 C
Where
T1.Co11 = T2.Col1
And T1.Col2=C.Col2
And More Conditions
Where Warehouse In ('W1','W2','W3','W4','W5')
Group By (Grouping_Condition,Warehouse)
The Above Query Gives Me Output Something Like Below:
Grouping_Condition Warehouse Total Total_Containers_Per_Warehouse Total_Containers Total_Pct
Containers_95_100 W1 5 10 60 50
Containers_Under_95 W1 5 10 60 50
Containers_95_100 W2 10 20 60 50
I've Got Report In The Below Format
W1 W2 W3 W4 W5 Total
Total_Containers 10 20 60
Containers_95_100 5 10 15
Containes_95_100_% 50 50 ????
I Need To Calculate The Total Percentage In The Above Table With ????
Any Help Is Much Appreciated..It appears as though you already have your groupings and counts per grouping, but require a ratio of each groupings count against all other counts. Is that correct ?
If so, try the new 11g analytic function, something like this:
select Grouping_Condition
,Warehouse
,ratio_to_report(Value) over () as Count_Ratio_over_Report
.. -
How to Create a Dynamic Crosstab Query?
Hi friends,
I have a table like:
DateOfSale SalesPerson SalesAmount
Which may have
any number of sales' staff (old/new workers) who have sold goods on different dates which may range at
any length of time.
Any suggestion for an appropriate query / method to derive a crosstab / pivot result as
SalesPerson Year1 Year2 Year3
With field SalesPerson representing
each of the staff member and all the amounts added
in terms of years, whatever the range may exist in time, instead of providing names and years in a hard-coded manner?
Looking forward for your expert advices.
Thanx in advance.
Best Regards, Faraz A Qureshilike this
;With CTE
AS
SELECT ROW_NUMBER() OVER (PARTITION BY SalesPerson ORDER BY DATEDIFF(yy,0,DateOfSale)) AS Seq,
DATEADD(yy,DATEDIFF(yy,0,DateOfSale),0) AS YrDate,
SalesPerson,
SUM(SalesAmount) AS SalesAmount
FROM Table
GROUP BY DATEDIFF(yy,0,DateOfSale),SalesPerson
SELECT SalesPerson,
[1] AS Year1,
[2] AS Year2,
[3] AS Year3,
[4] AS Year4
FROM CTE
PIVOT (MAX(SalesAmount) FOR Seq IN ([1],[2],[3],[4]))p
if you want to make this dynamic see
http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Crosstab Query re Grouping Data into Value Ranges
Hi
I am trying to analyse some data in a Crosstab & have a query re grouping.
The data contains sales transaction info such as selling price, quantity etc. I would like to create a grouping in the Crosstab based on a sale price range (eg £0 - £10, £10 - £20 etc) so that I can show the total quantity sold in each price range.
To date my method has been to create a formula with Select Case which identifies each transaction into a price range. I would then use this formula in my Crosstab. The main issue with this method is that there will be a large number of Cases & the possibility this will need to be added to / modified going forward.
Whilst I think this will work I am hoping there is better method to follow?
Thanks
JonHi Jamie,
Thank you for your help.
I'm looking to group in increments of 10 so it looks like the Floor function will do the trick, thank you.
I'll probably use an If statement to do a "block" of prices at either end of the scale (ie < 100 then 100, > 1000 then 1000+ else Floor ({Sales Field},10). Hopefully this way I'll reduce the overall no of rows.
Thanks again for your help.
Jon -
Hi..
I am new to MaxDB.I have an issue that to display row values into column.In sql we can use pivot function.Is there any crosstab function to display row values into column in MaxDB.
Thanks in Advance
Regards
BalasubramaniamHi,
you did not tell us the version of the MaxDB kernel you are using.
But there are two variants of CASE-function available in MaxDB :
<simple_case_function> and <searched_case_function>
<simple_case_function> ::=
CASE <check_expression>
WHEN <search_expression> THEN <result_expression>
[ELSE <default_expression>]
END
<check_expression> ::=
<expression>
<search_expression> ::=
<expression>
<result_expression> ::=
<expression>
<default_expression> ::=
<expression>
<searched_case_function> ::=
CASE
WHEN <search_condition> THEN <result_expression>
[ELSE <default_expression>])
END
<result_expression>::=
<expression>
<default_expression>::=
<expression>
The description can be found in the reference manual.
Elke
Maybe you are looking for
-
Redirect_URL...doesn't work in release 2?
Greetings: In a block of PL/SQL code (at the end), I want to send the user to another page (not call a procedure). I've used Redirect_URL successfully in Portal rel 1, but in release 2, it doesn't seem to be working. Question: Is there something diff
-
Calendar - possible to disable "smart" event details in titles?
I'm extremely frustrated by Mavericks Calendar and Reminders apps... I came from 10.6.x and things worked flawlessly. now, I cannot name an event with any sort of details in the title without it taking those details and applying them to the event its
-
How do I change my flash settings? I said I wanted to be prompted about flash wanting to store things on my computer but the prompts are too frequent and annoying!
-
How to get the correct value from check box
hi guys, here is a program to read data from IKPF. with the user tick on the check box, the program will retrive corresponding records based on the inventory counted (zstat) status. however i don't get the correct output with the following selection.
-
Db_keep and recycle_cache_size need help!!!
Hi all, I am trying to understand how the db_keep_cache_size and db_recycle_cache_size parameters are working as i know keep is used to retain the data block in the memory and recycle is used to eliminate the data block from memory( if i am wrong ple