Cross tab SQL
hi all , im a beginner in SQL and just discovering oracle and Java so i made a small database : 1 table
and i did the Database connectivity with my platform Java ( Netbeans) and every thing was okay.
i started looking for how to create a cross tab between 2 elements from my table but i couldn't find the SQL script to do it
my table is :
ID--NAME--SURNAME--LOCATION---GRADE
i want to have a cross tab between locations and the grade which calculatin the count of ID in each field so to create the interface in java so any help plz
i know its somethin classic but im just a new beginner and im trying to create a simple database application
i USE ORACLE 10G XE and NETBEANS
thnxx
Hello,
welcome to the Oracle forums. This is the forum for the tool "SQL Developer". Questions about SQL and PL/SQL have their own forum at PL/SQL
Best Regards
Marcus
Similar Messages
-
I have two tables
Tab1
Lookup Code
Lookup Type
Description
Tab 2
Bureau code
member code
partner code
x
y
z
My requirment is a bit typical (i guess)
Tab1
lookupcode lookup type desc
TRA Bureau code Sample Desc1
CCHK Membder Code Sample Desc2
CMSI Partner Code Sample Desc3
TAB2
Bureau Code Member Code Partner Code x y z
TRA CCHK CMSI 1 2 3
i want the data to be fetched in this fashion
x y z DESC1 DESC2 DESC3
1 2 3 Sample Desc1 Sample Desc2 Sample Desc3
How can i get the description of respective Lookup codes from tab1
while querying tab2.
I fell pivoting the table can do this but unable to frame the query properly
Please help me on this
Thanks in Advanceselect x,y,z
, (select "lookup type" from tab1 b where b.lookupcode=a."Bureau Code") Bcode
, (select "lookup type" from tab1 b where b.lookupcode=a."Member Code") Mcode
, (select "lookup type" from tab1 b where b.lookupcode=a."Partner Code ") pcode
from tab2 a; -
Hi,
I am using oracle 11g version.
I have a reporting requirement where in I have to produce a cross tab as explained below. Please help me in writing an SQL query to achieve this. Many thanks.
Sample data:
Customer product type
AAA DVD
AAA Tape
BBB Tape
CCC DVD
CCC Bluray
DDD DVD
DDD Tape
DDD Bluray
Logic
AAA BBB CCC DDD
DVD Tape Bluray DVD Tape Bluray DVD Tape Bluray DVD Tape Bluray
DVD 1 DVD DVD 1 DVD 1
Tape 1 Tape 1 Tape Tape 1 1
Bluray Bluray Bluray 1 Bluray 1 Final Output
No. of customers who purchased the products across all product types
DVD Tape Bluray
DVD 2 1
Tape 2 1 1
Bluray 1 1
Scripts:
create table cust_product(customer varchar2(5), product_type varchar2(10));
insert into cust_product values('AAA','DVD');
insert into cust_product values('AAA','Tape');
insert into cust_product values('BBB','Tape');
insert into cust_product values('CCC','DVD');
insert into cust_product values('CCC','Bluray');
insert into cust_product values('DDD','DVD');
insert into cust_product values('DDD','Tape');
insert into cust_product values('DDD','Bluray');Hi,
858747 wrote:
... Sample data:
Customer product type
AAA DVD
AAA Tape
BBB Tape
CCC DVD
CCC Bluray
DDD DVD
DDD Tape
DDD Bluray...
Final Output
No. of customers who purchased the products across all product types
` DVD Tape Bluray
DVD 2 1
Tape 2 1 1
Bluray 1 1
Sorry, I don't follow the logic. Try explaining in words, with specific examples.
Didn't 2 distinct customers, 'CCC' and 'DDD', buy both 'DVD' and 'Bluray'? Why aren't the results
` DVD Tape Bluray
DVD 2 2
Tape 2 1 1
Bluray 2 1 with 2's in the corners?
Assuming that was just mistake, you can do something like this:
WITH got_pairs AS
SELECT a.product_type AS product_a
, NVL (b.product_type, a.product_type) AS product_b
FROM cust_product a
LEFT OUTER JOIN cust_product b ON a.customer = b.customer
AND a.product_type != b.product_type
SELECT *
FROM got_pairs
PIVOT ( COUNT (*)
FOR product_b
IN ( 'DVD'
, 'Tape'
, 'Blueray'
ORDER BY CASE product_a
WHEN 'DVD' THEN 1
WHEN 'Tape' THEN 2
WHEN 'Bluray' THEN 3
END
;This assumes that the combination (customer, product_type) is unique, as it is in your sample data., and that the only product_types are the 3 in your sample data.
if those assumptions are not true, then post some revised sample data and results, that show what you want in those cases.
Sorry, I don't have an Oracle 11 database right now to test this.
I can (and did) test the outer join, that combines a product_type with itself only if it can't be combined with anything else.
Using a pre-Oracle 11 pivot technique, the following works:
WITH got_pairs AS
SELECT a.product_type AS product_a
, NVL (b.product_type, a.product_type) AS product_b
FROM cust_product a
LEFT OUTER JOIN cust_product b ON a.customer = b.customer
AND a.product_type != b.product_type
SELECT product_a AS product_type
, COUNT (CASE WHEN product_b = 'DVD' THEN 1 END) AS dvd
, COUNT (CASE WHEN product_b = 'Tape' THEN 1 END) AS dvd
, COUNT (CASE WHEN product_b = 'Bluray' THEN 1 END) AS dvd
FROM got_pairs
GROUP BY product_a
ORDER BY CASE product_a
WHEN 'DVD' THEN 1
WHEN 'Tape' THEN 2
WHEN 'Bluray' THEN 3
END
;Notice that the sub-query got_pairs is the same in both queries.
Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful!
Edited by: Frank Kulash on May 29, 2011 4:05 PM
Added Oracle 9 query. -
How create SQL for Cross tab in template
Hi,
I have been starting to build data templates using SQL to select the data I require. I noticed in the word template-building tool there is an option to create cross tab table. I have tried looking at the standard documentation. I have been unable to work out how I should structure the SQL in my data template to allow me to create a cross tab table in the template?
Thanks,
MarkPost Author: SunilKanta
CA Forum: General
Yes, I had done exactly the same but when tried to display the subreport in new page, some portion of the cross tab is displayed. The page width is not increased proportionately.
i have passed that sub report in footer of main report.
But when i overlap this sub report with other cross tabs already present in the main report i can see full width view of sub report. -
"Can Grow" property on Cross-Tab object can not be unlock
I am using Crystal Reports XI. My report uses a Cross-Tab object via SQL server. I am having problem making my data column (Field Row) to increase dynamically in height when my data size increases. Since the "Can Grow" property in the Format Editor is locked, it would not let me set the "Can Grow" to true to enable this function. How do I unlock the "Can Grow" function so I can set it to true?
The only other option I can think of would be to build a virtual cross tab, but in many cases, especially when the number of 'column' values is dynamic, this is not possible.
-
Hi,
i would like to add additonal data to the row-label in a cross-tab.
....................... C1 C2 C3
Customer1
.... add.Data1
Customer2
.... add.Data2
Customer3
.... add.Data3
How can i do that?
The link between the Customer-Table and the Extra-Data is the customer-id and a Date-Field (parameter of the report - used for filtering on a date-basis).
Table for extra data:
customer-id date amount
DATE is a parameter of the report.
Is there any way to do this?
(I use CR XI).
Result should look like this:
Selected Date (Parameter): 2009-02-02
...................................................... C1 C2 C3
Customer1 +
....amount on 2009-02-02 for C1
Customer2 +
....amount on 2009-02-02 for C2
Customer3 +
....amount on 2009-02-02 for C3
THX in advance,
MarkusHi,
Lets phrase it differently again
i have a second table from which i would like to add additional information to the row-information in a cross-tab.
customer.... date ... amount
Cust1....2009-02-01.... 10
Cust1....2009-03-01.... 15
Cust1....2009-04-01.... 77
Cust2 ........
Cust3 ........
I need ONLY the first amount from the starting-date in the CROSS-Tab.
The starting-date is a parameter in the report.
If i put there the linked amount-field i get a row for each different date.
I need only one row per customer with the first amount from date 1. (the parameter-date-value)
So if i enter 2009-03-01 as the parameter, i would like a cross tab with a row-name of:
"Customer1 + ChrW(13) + 15 "
It works with a SQL-Expression (named "StartSaldo") like:
(Select Saldo from Goldbeck_Saldo where D_Date = '20090301'
and "Goldbeck_Saldo"."I_PERSID"="BaseTable"."I_PERSID")
and a row name of "Customer.Name + ToText({%StartSaldoSQL})
However the Date "20090201" is hard-coded there.
I can find no way to make the Date from the SQL-Expression soft-coded (pass the parameter to the scalar SQL-Expression). According to another forum-post this is not possible.
THX
Markus
Edited by: Cumulus7 on Apr 27, 2009 4:25 PM -
Issue with passing parameters through Java-JSP in a report with cross tab
Can anyone tell me, if there's a bug in Java SDK in passing the parameters to a report (rpt file) that has a cross tab in it ?
I hava report that works perfectly fine
with ODBC through IDE and also through browser (JSP page)
(ii) with JDBC in CR 2011 IDE
the rpt file has a cross tab and accpts two parameters.
When I run the JDBC report through JSP the parameters are never considered. The same report works fine when I remove the cross tab and make it a simple report.
I have posted this to CR SDK forum and have not received any reply. This have become a blocker and because of this our delivery has been postponed. We are left with two choices,
Re-Write the rpt files not to have cross-tabs - This would take significant effort
OR
(ii) Abandon the crystal solution and try out any other java based solutions available.
I have given the code here in this forum posting..
CR 2011 - JDBC Report Issue in passing parameters
TIA
DRG
TIA
DRGMr.James,
Thank you for the reply.
As I stated earlier, we have been using the latest service pack (12) when I generated the log file that is uploaded earlier.
To confirm this further, I downloaded the complete eclipse bundle from sdn site and reran the rpt files. No change in the behaviour and the bug is reproducible.
You are right about the parameters, we are using {?@Direction} is: n(1.0)
{?@BDate} is: dt(d(1973-01-01),t(00:00:00.453000000)) as parameters in JSP and we get 146 records when we directly execute the stored procedure. The date and the direction parameter values stored in design time are different. '1965-01-01' and Direction 1.
When we run the JSP page, The parameter that is passed through the JSP page, is displayed correctly on the right top of the report view. But the data that is displayed in cross tab is not corresponding to the date and direction parameter. It corresponds to 1965-01-01 and direction 1 which are saved at design time.
You can test this by modifying the parameter values in the JSP page that I sent earlier. You will see the displayed data will remain same irrespective of the parameter.
Further to note, Before each trial run, I modify the parameters in JSP page, build them and redeploy so that caching does not affect the end result.
This behaviour, we observe on all the reports that have cross-tabs. These reports work perfectly fine when rendered through ODBC-ActiveX viewer and the bug is observable only when ran through Java runtime library. We get this bug on view, export and print functionalities as well.
Additionally we tested the same in
With CR version 2008 instead of CR 2011.
(ii) Different browsers ranging from IE 7 through 9 and FF 7.
The complete environment and various softwares that we used for this testing are,
OS : XP Latest updates as on Oct 2011.
App Server: GlassFish Version 3 with Java version 1.6 and build 21
Database server ; SQL Server 2005. SP 3 - Dev Ed.
JTds JDBC type 4 driver version - 1.2.5 from source forge.
Eclipse : Helios along with crystal libraries directly downloaded from SDN site.
I am uploading the log file that is generated when rendering the rpt for view in IE 8
Regards
DRG -
Record selection issue in cross tab.
Hello!
I have a record filtering problem. I tried many scenarios, and searched this forum but I cannot find an solution.
I have a sub-report that contains a cross tab that provides a few summarized fields.
I have two tables: a table with category of events : (field catID and Catname) and an event table with a CatID, a date field and others number field I use in the cross tab.
I want my cross tab to show one row per category. The Catname and the summaries.
Now all is working fine but for one issue. I need to select my event according to a time bracket.
So I created two time parameters (start and end) and select the event dates between these two dates.
Now, when selected, any category that does not have an event between these dates are not displayed. I would like them to be shown with "o" values.
There must be a way of doing this. I just cannot find it.
EstherIn order for Crystal to show data, it must be given data to show!
You will need to base your subreport on an SQL Command. In that command, put the current SQL used by the report. To this, do a UNION to a select that selects the category name, and a zero for each field that you are summing in the crosstab.
As a simplified example, suppose the original SQL was (MS SQL):
select c.catname, sum(e.quantity) as Quantity
from categories c, events e
where c.catid = {?catid parm}
and c.catid = e.catid
and e.date between {?start} and {?end}
This would be changed to
select c.catname, sum(e.quantity) as Quantity
from categories c, events e
where c.catid = {?catid parm}
and c.catid = e.catid
and e.date between {?start} and {?end}
UNION
select c.catname, 0 as Quantity
from categories c
where c.catid = {?catid parm}
This will return an additional zero record, regardless of what data the original query returns, thus giving Crystal the data needed to display. Note that the zero value will not affect the results in any way, except causing a zero to be displayed if no data is returned from the original query.
Just remember that the second SELECT in the UNION has to have the same number of fields, of the same data type, as the first SELECT.
HTH,
Carl -
How to display recordnumber for each row in cross tab?
<p>Hi.. </p><p>I am using Crystal Report XI,with the database Microsoft SQL Server. I have 2 questions regarding Cross Tab.</p><p>1. How to limiting record per row and per column in Cross Tab? For example,at one page the report printing 20 records per row and 7 records per columns.</p><p>2. I would like to display recordnumber for each row that printing in Cross tab. How crystal reports can handle this?</p><p>Can anyone can help me out on this? </p><p>Please kindly advise.</p><p>AN </p><p> </p><p> </p>
<p>Dear Kathryn,</p><p> </p><p>I did used DisplayString as suggested by you. The result work fine until I add more data to this cross tab. I used this formula : </p><p> global numbervar pager;</p><p>recordnumber();</p><p>pager := pager + 1; </p><p> if pager > 0 then totext(pager - 1,0) </p><p> </p><p>The result come out in decending order for each row. </p><p>SN Name </p><p>5 abc<br /></p><p> 4 def</p><p>3 fig<br /></p><p>2 klm<br /></p><p>1 opq</p><p> Is that anything wrong with my formula?<br /> </p><p>Please kindly advise.</p><p>-AN- </p><p> </p><p> </p>
-
How can I compare two summary field in cross-tab?
<p>Dear expert:</p><p>I have one question for how can I compare two summary field in cross-tab? I have following cross-table:</p><p>Type Sector1 Sector2 Sector3 Total </p><p>Outlook 10 11 9 30 </p><p>Target 5 3 1 9</p><p>I want to compare the summary field(total) relationship percent, I want to get "9/30". Someone told me I must create the DB view or table via SQL, then can implete in Crystal Report. Can I implete it in Crystal Report via fomula or other function?</p><p>Thanks so much for your warm-hearted help!</p><p>Steven</p>
Hello Steven, yes you can compare summary fields, If you are comparing Summary to Target, or vice versa - you can do it within Crystal Reports.
1. In Suppress conditional formula, create 2 Global variables: CurrentOutlook and CurrentTarger and get the current value.
2. In Display String formula for Total show ToText(CurrentTarget/CurrentOUtlook) + "%".
For more difficult cases of compariing fields in cross--tab, you may look into http://www.relasoft.net/KB10001.html.
Best,
Alexander -
SAP Web Intelligence -Comparing subsequent columns in cross tab
Hello,
I am new in SAP web intelligence , I need formula (Not a SQL Query) to find difference of values between subsequent columns in cross tab. Please find attached excel for more details
Thanks & RegardsTry something like in below screenshot-
Craete variable
Diff Amount2=Previous([Amount2])-[Amount2]
~Anuj -
Cross Tab Column Header and Embedded or Calculated Member
Hello All
I am needing some help with a Cross Tab in CR2008.
My Cross Tab look as follows:
Rows______________Columns
......................................Fiscal Year
Account Number...........Summarized Field (Value Field)
The report spans three Fiscal Years but not all accounts have three Fiscal Years worth of data so some Cross tabs start 2009, 2008, 2007, Some report 2008 and 2007, Some just 2007 (and other variations). To get my cross tab working correctly I need to create a formula that get the CurrentColumnIndex based upon the Fiscal Year. e.g. If columnd header = 2009 column index = 0.
Can anyone advise how I would go about this?
Thanks
PhillipPhillip, go to your data source, and see if you can add a new connection,
one of those options should be (Command)
if you can add a Command, then you can put the SQL in the command section.
You will need to add the Command as a data source, and remove the old
data source once the command is added, you will be able to edit it if needed. -
Cross tab report-dyanamic columns for months and quarterly sum
Hi all,
I work on report creation in BI Publisher.I need to display values in a cross tab report in a way that it shows data for 3 months and then a column for its quarterly sum.
For ex:-
Market --Jan Feb Mar Q1_sum Apr May Jun Q2_sum ---------------like wise for n months
Market1 100 --80 --30 -- 210 --10 -- 80 --90 --210
Market2 120 --90 --40 --250 --100 --70 --30 --200
Market3 130 --70 --60 --260 --140 -- 0 --40 --180 ('--' just to maintain indentation)
The values of number of months( date range) and the names of market are derived dyanamically .
The code from my sql query presently shows months-range (Jan ,feb,mar..), Quarterly sum to be displayed, Market names etc as child elements in multiple occurences main Query set.
<Main Query>
<Market>abc</Market>
<Region>abc</Region>
<Months-Range>abc</Months-Range>
<Quarterly_sum>abc</Quarterly_sum>
<Main Query>
<Main Query>
</Main Query>
Please guide me on code in rtf template for the same.
Thanks
Edited by: user9061488 on Jul 13, 2010 1:32 AM
Edited by: user9061488 on Jul 13, 2010 3:48 AMHi,
Do u have time dim in your metadata??
If not,
Create a time dimension year,quater,month,day
http://lh4.ggpht.com/_rhCtHYLiamQ/S7PQvxYBbzI/AAAAAAABZXI/ef_Ur9AmyUo/s800/04_year_quarter_bmm.jpg
After that in fact table by using the (ago/todate) function ....pull the respective columns to pivot table columns section(date column) and measures col in measures section and enable the grand total in columns section so that it will show grand total for every quarter
thanks,
saichand.v -
Cross-tab cell padding: how to change
Post Author: EnRoute
CA Forum: General
I am trying to minimize the height of the cells of a cross-tab object. I can re-size the text, but that doesn't change the padding between the text and the cell border lines. There is more padding than I want. If I reduce the text height any more, the bottoms of the letters g, j, p, q, and y are truncated, even though there is a significant amount of whitespace below. Is there a way to change the amount of cell padding?
Product: Crystal Reports
Version: 10.0.0.533
Patches Applied:
Operating System(s): Windows XP
Database(s): Microsoft SQL Server
Error Messages: Not applicableSteps to Reproduce: Place a cross-tab object on a report.Post Author: SKodidine
CA Forum: General
One way to do it in CR XI is to right click on the cross tab and then Cross Tab Expert and in the Customize Style tab, uncheck Show Cell Margins. That will eliminate the cell padding of white space. -
I am currently using crystal to design a detailed report which is using multiple tables from an sql source.
If I take 2 of the tables (Call & Decision) and insert fields (Call.ID and Decision.Rule) into the detail section, they will appear as below because the reason field from the decision table has multiple outcomes so repeats itself with each one for 1 call ID:
Call ID Decision Rule Decision Decision PreviousCall Rule Decision (formula field)
1 Coverage Accept
1 Exclusion Accept
1 PreviousCall Accept
2 Coverage Accept
2 Exclusion Accept
2 PreviousCall Decline Decline
If I group the report by Call ID, this resolves the issue above and using formula fields (one example given above) I can determine what each call ID was declined (if any). From then I export into excel then create a pivot table to display in tabular form. The Pivot table counts the number each Decision.Rule which has been declined as so:
Count of Coverage Declines 33
Count of Exclusion Declines 43
Count of PreviousCall Declines 25
and so on
However I have now come across a hurdle in that the number of records I am exporting into excel (2003) exceed the number allowed. Also it is too much of a manual job from start to finish, so want to achieve the same output using Crystal Cross Tabs. Initial attempts have been unsuccessful mostly due it multi counting each Call ID, thus giving an inaccurate result. If I group by call id the table displays each one within the row whereas I just want to count the declines for each Decision.rule as a whole.
Any ideas?
Thanks.From your data source, return Call ID, Decision Rule, and Accept /Decline:
Call.ID Decision.Rule Decision.Decision
1 Coverage Accept
1 Exclusion Decline
(etc)
In your cross tab expoert, put Call.ID in the Rows, and Decision.Rule and Decision.Decision in your Columns. For the Summarized Fields, just use Count of Decision.Decision.
I believe that will get you what you are looking for, more or less. (E.g., if you only want declines, exclude Accept records...)
HTH,
Carl
Maybe you are looking for
-
Problem in using AVTransmit2 and AVReceive2
Hello, I am very new to JMF. I start to work on it and i teke sample example from http://java.sun.com/products/java-media/jmf/2.1.1/solutions/AVTransmit.html and http://java.sun.com/products/java-media/jmf/2.1.1/solutions/AVReceive.html. In AVTransmi
-
Oracle deinstall doesnt work. I guess you have to reinstall windows?
we could not get 11g R2 to work on a new Windows 2008 server. So now we need to remove it. According to this document: http://docs.oracle.com/cd/B28359_01/install.111/b32007/deinstall.htm#CIHJCJHC The correct way to uninstall is to: 1) Start Oracle U
-
Cups and "waiting for printer to become available"
Hi all, i have a problem with cups (i don't know since when), when i try to print something i receive the message: "waiting for printer to become available" And i'm aware that this problem happens when you have usblp loaded. So first of all i checked
-
I have two questions: 1. When I first got an iPod touch (4th gen) I synced it (to start it up) on my mom's Mac Laptop. I finally got my own laptop and tryed to sync my music and info from my iPod to my ASUS laptop, but it said that the only way to do
-
Hi there, I have a MBP (first one, Intel Core Duo, not Core 2 Duo). I have all connections from DVI to HDMI, SCART, S-Video, etc, but I would like to know if there is a way to get the DVI (digital HD) to Component (Analogue HD)? Basically, I want to