Cross tab query
Hi guys,.
I hope someone can help. I'm trying to generate a cross-tab query that displays the total output per month in our production environment.
I used the query here http://www.dba-oracle.com/oracle_tips_crosstab_sql.htm and manipulated to
select DECODE(GROUPING(mtr.model_range||' '||mtr.oven_cavity), 1, 'All Cavities', mtr.model_range||' '||mtr.oven_cavity) AS "Model Range Cavity" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'JAN' THEN 1 else null end) "JAN" --,SUM(SP.INPUT_QUANTITY(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'JAN' THEN 1 else null end)) "JAN" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'FEB' THEN 2 else null end) "FEB" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'MAR' THEN 3 else null end) "MAR" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'APR' THEN 4 else null end) "APR" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'MAY' THEN 5 else null end) "MAY" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'JUN' THEN 6 else null end) "JUN" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'JUL' THEN 7 else null end) "JUL" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'AUG' THEN 8 else null end) "AUG" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'SEP' THEN 9 else null end) "SEP" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'OCT' THEN 10 else null end) "OCT" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'NOV' THEN 11 else null end) "NOV" ,count(case WHEN substr(NVL(sp.START_RUN_TIME,sp.SCHEDULED_START_DATE),4,3) = 'DEC' THEN 12 else null end) "DEC" ,count(case when 1 = 1 then 1 else null end) "Total" from XXMEL_PROVISA_SCHEDULES_PLAN sp , XXMEL_PVS_WORKS_ORDER_LIST wl , xxmel_pqm_cells pc , xxmel_provisa_model_to_range mtr WHERE 1=1 AND sp.part_number = MTR.MODEL_NAME (+) AND sp.work_unit = pc.pk_cell_id AND sp.RUN_QUANTITY> 0 And sp.input_quantity >0 AND SP.PART_NUMBER = wl.MODEL (+) AND plan_id = :P17_PLAN_ID and simulation_id = :P17_SIM_ID and mtr.oven_cavity is not null group by rollup(mtr.model_range||' '||mtr.oven_cavity)
This query works OK giving me the count of how many lines there are for each month, but I have to do is to add the field named MS. INPUT_QUANTITY for each month.
I get the error message "ORA-00904:"SP"". "" ' INPUT_QUANTITY': invalid identifier "when you include the commented line on line 4 of the above query. SP. INPUT_QUANTITY is a valid column
I use it on an instance of Oracle 10g.
Thank you
Chris
Select | ||
DECODE (GROUPING (mtr.model_range |)) » '|| MTR.oven_cavity), 1, "all cavities, mtr.model_range | '|| MTR.oven_cavity) AS "model range cavity. | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "JAN" THEN 1 other trailing null) "JAN". | ||
, SUM ((affaire QUAND substr (NVL (sp.)))) START_RUN_TIME, Ms. SCHEDULED_START_DATE), 4, 3) = "JAN" THEN MS. INPUT_QUANTITY else 0 end)) "JAN". | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "FEB" THEN 2 other trailing null) "FEB. | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "MAR" THEN 3 other trailing null) "MAR." | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "APR" AND 4 other trailing null) "APR." | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "MAY" THEN 5 other trailing null) «CAN» | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "JUN" THEN 6 other trailing null) "JUN". | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "JUL" THEN 7 other trailing null) "JUL". | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "August" AND 8 other trailing null) "AUG. | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "SEP" THEN 9 other trailing null) "MS." | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "OCT" THEN 10 other trailing null) 'OCT. | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "NOV" AND 11 other trailing null) "NOV. | ||
, count (case WHEN substr (NVL (sp.) START_RUN_TIME, Ms. (SCHEDULED_START_DATE), 4, 3) = "DEC" AND 12 other trailing null) "DEC". | ||
-- | , County (cases where 1 = 1 and then 1 other trailing null) 'Total '. | |
count (*) 'Total' | ||
of XXMEL_PROVISA_SCHEDULES_PLAN sp | ||
, | Wl XXMEL_PVS_WORKS_ORDER_LIST | |
, | xxmel_pqm_cells pc | |
, | xxmel_provisa_model_to_range mtr | |
WHERE 1 = 1 | ||
AND sp.part_number = MTR. MODEL_NAME | ||
AND sp.work_unit = pc.pk_cell_id | ||
AND Ms. RUN_QUANTITY > 0 | ||
And sp.input_quantity > 0 | ||
AND MS. PART_NUMBER = wl. MODEL | ||
AND the plan_id = argument: P17_PLAN_ID | ||
and simulation_id =: P17_SIM_ID | ||
and mtr.oven_cavity is not null | ||
Group of rollup (mtr.model_range |) » '|| MTR.oven_cavity); |
----
Ramin Hashimzade
Tags: Database
Similar Questions
-
Need a cross tab query nickname
Do not know how to proceed. I have a table with content that
EmpID
empnm
Office
Phone
and another table with
EmpID
workdt
NOTIN
I need to view data such as
Office phone EmpID empnm 1/1/12 2/1/12 1/3/12 1/4/12 5/1/12 1/6/12 1/7/12
123 x 123 x x joe
467 sam 333
Bill 777 444 x x
The data in the employee file looks like this
Empnm EmpID desk phone
Joe 123 123
467 sam 333
Bill 777 444
The data in the file workdates looks like this
EmpID workdt notin
123 1/1/12 x
123 1/2/12
123 1/3/12 x
123 1/4/12 x
123 1/5/12
123 1/6/12
123 1/7/12
467 1/1/12
467 1/2/12
467 1/3/12
467 1/4/12
467 1/5/12
467 1/6/12
467 1/7/12
777 1/1/12
777 1/2/12 x
777 1/3/12
777 1/4/12
777 1/5/12 x
777 1/6/12
777 1/7/12Hello
There are more options, but I show two below:
with empdef as ( select 123 empid, 'Joe' empnm, '123' office, cast(null as varchar2(10)) phone from dual union all select 467, 'Sam', '333', null from dual union all select 777, 'Bill', '444', null from dual ) ,workdata as ( select 123 empid, to_date('01-JAN-12', 'dd-mon-yy') workdt, 'X' notin from dual union all select 123, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all select 123, to_date('03-JAN-12', 'dd-mon-yy'),'X' from dual union all select 123, to_date('04-JAN-12', 'dd-mon-yy'),'X' from dual union all select 123, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all select 123, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all select 123, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('02-JAN-12', 'dd-mon-yy'),'X' from dual union all select 777, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('05-JAN-12', 'dd-mon-yy'),'X' from dual union all select 777, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('07-JAN-12', 'dd-mon-yy'),null from dual ) select e.empid ,e.empnm ,e.office ,e.phone ,max(case when w.workdt = to_date('01-01-2012', 'dd-mm-yyyy') then notin else null end) "1/1/12" ,max(case when w.workdt = to_date('02-01-2012', 'dd-mm-yyyy') then notin else null end) "1/2/12" ,max(case when w.workdt = to_date('03-01-2012', 'dd-mm-yyyy') then notin else null end) "1/3/12" ,max(case when w.workdt = to_date('04-01-2012', 'dd-mm-yyyy') then notin else null end) "1/4/12" ,max(case when w.workdt = to_date('05-01-2012', 'dd-mm-yyyy') then notin else null end) "1/5/12" ,max(case when w.workdt = to_date('06-01-2012', 'dd-mm-yyyy') then notin else null end) "1/6/12" ,max(case when w.workdt = to_date('07-01-2012', 'dd-mm-yyyy') then notin else null end) "1/7/12" from empdef e join workdata w on (e.empid = w.empid) group by e.empid ,e.empnm ,e.office ,e.phone order by e.empid ; EMPID EMPNM OFFICE PHONE 1/1/12 1/2/12 1/3/12 1/4/12 1/5/12 1/6/12 1/7/12 ----- ----- ------ ---------- ------ ------ ------ ------ ------ ------ ------ 123 Joe 123 X X X 467 Sam 333 777 Bill 444 X X
or with the pivot clause:
with empdef as ( select 123 empid, 'Joe' empnm, '123' office, cast(null as varchar2(10)) phone from dual union all select 467, 'Sam', '333', null from dual union all select 777, 'Bill', '444', null from dual ) ,workdata as ( select 123 empid, to_date('01-JAN-12', 'dd-mon-yy') workdt, 'X' notin from dual union all select 123, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all select 123, to_date('03-JAN-12', 'dd-mon-yy'),'X' from dual union all select 123, to_date('04-JAN-12', 'dd-mon-yy'),'X' from dual union all select 123, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all select 123, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all select 123, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all select 467, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('02-JAN-12', 'dd-mon-yy'),'X' from dual union all select 777, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('05-JAN-12', 'dd-mon-yy'),'X' from dual union all select 777, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all select 777, to_date('07-JAN-12', 'dd-mon-yy'),null from dual ) select * from empdef e join workdata w using (empid) pivot(max(notin) for workdt in (to_date( '01-01-2012', 'mm-dd-yyyy') as "1/1/12" ,to_date( '01-02-2012', 'mm-dd-yyyy') as "1/2/12" ,to_date( '01-03-2012', 'mm-dd-yyyy') as "1/3/12" ,to_date( '01-04-2012', 'mm-dd-yyyy') as "1/4/12" ,to_date( '01-05-2012', 'mm-dd-yyyy') as "1/5/12" ,to_date( '01-06-2012', 'mm-dd-yyyy') as "1/6/12" ,to_date( '01-07-2012', 'mm-dd-yyyy') as "1/7/12" ) ) ; EMPID EMPNM OFFICE PHONE 1/1/12 1/2/12 1/3/12 1/4/12 1/5/12 1/6/12 1/7/12 ----- ----- ------ ---------- ------ ------ ------ ------ ------ ------ ------ 467 Sam 333 123 Joe 123 X X X 777 Bill 444 X X
Kind regards
Peter
-
Hello
I'm using the version of oracle 11g.
I have a requirement where I have to produce a cross-tab as explained below. Please help me write a SQL query to do this. Thank you very much.
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');
Hello
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
N ° of guests who have purchased products for all types of product` DVD Tape Bluray DVD 2 1 Tape 2 1 1 Bluray 1 1
Sorry, I don't follow the logic. Try to explain in words, with specific examples.
Doesn't have 2 separate clients, 'CCC' and 'DDD', buy 'DVD' and 'Bluray '? Why aren't the results` DVD Tape Bluray DVD 2 2 Tape 2 1 1 Bluray 2 1
with 2 in the corners?
Assuming it was just error, 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 in your example of data., and that only product_types is 3 in your sample data.
If these assumptions are not true, then after a few revised sample data and results, which show what you want in these cases.Sorry, I don't have an Oracle 11 database now to test this.
I can (and has) test the outer join, which combines a product_type with him that if he can not be combined with any other thing.Using a technique of 11 pivot before Oracle, 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 ;
Note that the got_pairs of the subquery is identical in the two motions.
Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!
Published by: Frank Kulash, may 29, 2011 16:05
Oracle 9 append query. -
Cross Tab with group by period
Good afternoon
I wonder if some can help me with this query, I am writing?
The cross-tab is for columns 1 to 31, representing the days of the month, sum of the quantity of an article sold.
In addition the company description.
I would then finish with 3 entrances in the results for each company, but these are for the sum of the quantity of items in the following periods: -.
Breakfast: 01:00 - 10:00
Lunch: 11:00 - 14:00
Dinner: 17:00 - 22:30
Yes, the company is closed for the missing periods, for example 10:00-11:00 & 14:00 to 17:00.
Test case:
With similar results to: -.CREATE TABLE COMPANIES ( "ID" NUMBER(9,0), "CODE" NUMBER(8,0), "DESCRIPTION" VARCHAR2(40 CHAR), CONSTRAINT "PK_COMPANIES" PRIMARY KEY ("ID") ); INSERT INTO COMPANIES VALUES (1,1,'COMPANY A'); INSERT INTO COMPANIES VALUES (2,2,'COMPANY B'); INSERT INTO COMPANIES VALUES (3,3,'COMPANY C'); CREATE TABLE CUSTOMERS ( "ID" NUMBER(9,0), "CODE" VARCHAR2(30 CHAR), "CARD_NUM" VARCHAR2(30 CHAR), "DESCRIPTION" VARCHAR2(40 CHAR), "COMPANY_ID" NUMBER(9,0), CONSTRAINT "PK_CUSTOMERS" PRIMARY KEY ("ID") ); INSERT INTO CUSTOMERS VALUES (1,'001','001','A CUSTOMER', 1); INSERT INTO CUSTOMERS VALUES (2,'002','002','A CUSTOMER', 2); INSERT INTO CUSTOMERS VALUES (3,'003','003','A CUSTOMER', 3); INSERT INTO CUSTOMERS VALUES (4,'004','004','A CUSTOMER', 1); INSERT INTO CUSTOMERS VALUES (5,'005','005','A CUSTOMER', 2); INSERT INTO CUSTOMERS VALUES (6,'006','006','A CUSTOMER', 1); CREATE TABLE ARTICLES ( "ID" NUMBER(9,0), "CODE" VARCHAR2(20 CHAR), "DESCRIPTION" VARCHAR2(40 CHAR), CONSTRAINT "PK_ARTICLES" PRIMARY KEY ("ID") ); INSERT INTO ARTICLES VALUES (1,'001', 'A Meal'); CREATE TABLE TRANSACTIONS ( "ID" NUMBER(9,0), "TILL_ID" NUMBER(9,0) NOT NULL ENABLE, "SHOP_ID" NUMBER(9,0) NOT NULL ENABLE, "OPERATOR_ID" NUMBER(9,0), "TRANS_NUM" NUMBER(5,0) NOT NULL ENABLE, "SPLIT_NUM" NUMBER(5,0), "TRANS_DATE" DATE NOT NULL ENABLE, "TOTAL_AMOUNT" NUMBER(12,2) NOT NULL ENABLE, "BOOKKEEPING_DATE" DATE NOT NULL ENABLE, "CARD_NUM" VARCHAR2(30 CHAR), CONSTRAINT "PK_TRANSACTIONS" PRIMARY KEY ("ID") ); INSERT INTO TRANSACTIONS VALUES (1,1,1,1,1,NULL,to_date('27.04.2011 10:30:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'001'); INSERT INTO TRANSACTIONS VALUES (2,1,1,1,1,NULL,to_date('27.04.2011 10:31:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'002'); INSERT INTO TRANSACTIONS VALUES (3,1,1,1,1,NULL,to_date('27.04.2011 10:32:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'003'); INSERT INTO TRANSACTIONS VALUES (4,1,1,1,1,NULL,to_date('27.04.2011 10:33:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'004'); INSERT INTO TRANSACTIONS VALUES (5,1,1,1,1,NULL,to_date('27.04.2011 10:34:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'005'); INSERT INTO TRANSACTIONS VALUES (6,1,1,1,1,NULL,to_date('27.04.2011 10:35:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'006'); INSERT INTO TRANSACTIONS VALUES (7,1,1,1,1,NULL,to_date('27.04.2011 14:30:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'001'); INSERT INTO TRANSACTIONS VALUES (8,1,1,1,1,NULL,to_date('27.04.2011 14:31:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'002'); INSERT INTO TRANSACTIONS VALUES (9,1,1,1,1,NULL,to_date('27.04.2011 14:32:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'003'); INSERT INTO TRANSACTIONS VALUES (10,1,1,1,1,NULL,to_date('27.04.2011 14:33:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'004'); INSERT INTO TRANSACTIONS VALUES (11,1,1,1,1,NULL,to_date('27.04.2011 14:34:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'005'); INSERT INTO TRANSACTIONS VALUES (12,1,1,1,1,NULL,to_date('27.04.2011 14:35:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'006'); INSERT INTO TRANSACTIONS VALUES (13,1,1,1,1,NULL,to_date('27.04.2011 22:00:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'001'); INSERT INTO TRANSACTIONS VALUES (14,1,1,1,1,NULL,to_date('27.04.2011 22:01:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'002'); INSERT INTO TRANSACTIONS VALUES (15,1,1,1,1,NULL,to_date('27.04.2011 22:02:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'003'); INSERT INTO TRANSACTIONS VALUES (16,1,1,1,1,NULL,to_date('27.04.2011 22:03:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'004'); INSERT INTO TRANSACTIONS VALUES (17,1,1,1,1,NULL,to_date('27.04.2011 22:04:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'005'); INSERT INTO TRANSACTIONS VALUES (18,1,1,1,1,NULL,to_date('27.04.2011 22:05:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'006'); CREATE TABLE TRANS_ARTICLES ( "TRANSACTION_ID" NUMBER(9,0) NOT NULL ENABLE, "ARTICLE_ID" NUMBER(9,0) NOT NULL ENABLE, "QTY_WEIGHT" NUMBER(10,3) NOT NULL ENABLE, "PRICE" NUMBER(10,2) NOT NULL ENABLE, CONSTRAINT "PK_TRANS_ARTICLES" PRIMARY KEY ("TRANSACTION_ID") ) INSERT INTO TRANS_ARTICLES VALUES (1,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (2,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (3,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (4,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (5,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (6,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (7,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (8,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (9,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (10,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (11,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (12,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (13,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (14,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (15,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (16,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (17,1,1,0.01); INSERT INTO TRANS_ARTICLES VALUES (18,1,1,0.01);
This is the Group of periods which is I don't know how to do.1 Company A - 01:00 10:00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 Company A - 11:00 14:00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 Company A - 17:00 22:30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 2 Company B - 01:00 10:00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 2 Company B - 11:00 14:00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 2 Company B - 17:00 22:30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0
Thank you & best regards,
AndrewHello
Here's a way to do it:
WITH all_time_slots AS ( SELECT '01:00 - 11:00' AS label, 1 / 24 AS start_time, 11 / 24 AS end_time FROM dual UNION ALL SELECT '12:00 - 15:00', 12 / 24, 15 / 24 FROM dual UNION ALL SELECT '17:00 - 23:30', 17 / 24, 23.5 / 24 FROM dual ) , all_days AS ( SELECT LEVEL AS day_of_month FROM dual WHERE LEVEL IN (1, 27, 31) -- ***** FOR TESTING ONLY ***** CONNECT BY LEVEL <= 31 ) , inner_joins AS ( SELECT EXTRACT (DAY FROM tr.bookkeeping_date) AS day_of_month , tr.trans_date , ta.qty_weight , cu.company_id FROM articles ar JOIN trans_articles ta ON ta.article_id = ar.id JOIN transactions tr ON tr.id = ta.transaction_id JOIN customers cu ON cu.card_num = tr.card_num WHERE ar.description = 'A Meal' AND tr.bookkeeping_date >= DATE '2011-04-01' AND tr.bookkeeping_date < DATE '2011-05-01' ) , unpivoted_data AS ( SELECT co.description , ad.day_of_month , NVL (ij.qty_weight, 0) AS weight_0 , ts.label FROM companies co CROSS JOIN all_time_slots ts CROSS JOIN all_days ad LEFT OUTER JOIN inner_joins ij ON ij.company_id = co.id AND ij.day_of_month = ad.day_of_month AND ij.trans_date - TRUNC (ij.trans_date) BETWEEN ts.start_time AND ts.end_time ) SELECT * FROM unpivoted_data PIVOT ( SUM (weight_0) FOR day_of_month IN ( 1 AS day_1 , 27 AS day_27 , 31 AS day_31 ) ) ORDER BY description , label ;
Ouput, given the example of data that you changed it about an hour ago:
DESCRIPTION LABEL DAY_1 DAY_27 DAY_31 ----------- ------------- ---------- ---------- ---------- COMPANY A 01:00 - 11:00 0 3 0 COMPANY A 12:00 - 15:00 0 3 0 COMPANY A 17:00 - 23:30 0 3 0 COMPANY B 01:00 - 11:00 0 2 0 COMPANY B 12:00 - 15:00 0 2 0 COMPANY B 17:00 - 23:30 0 2 0 COMPANY C 01:00 - 11:00 0 1 0 COMPANY C 12:00 - 15:00 0 1 0 COMPANY C 17:00 - 23:30 0 1 0
Sorry, I'm short on time right now. I'll try to post an explanation in 4 hours approximately.
See my next post for an explanation.Published by: Frank Kulash, 28 April 2011 21:29
-
How to create Cross Tab using Desktop
Hello world
We use Sundard banner (universities) with discoverer.
I would like to create a cross-tab
| Final note
|_______________________________
Title of the course.
|
|
Valid values of rank are: HP - honors
H - honors
P past
Suppose that we had 3 students for the class: emergency medicine
George Washington - HP
John Adams - HP
Abraham Lincoln - H
Want a query to look like this:
| HP | H | P
|_________ |_____|_________________
Emergency medicine | 2. 1
|
|
Is this possible using Desktop, pls advise... thx, SandraHello
Yes, you should be able to create a cross tab report in Discoverer Desktop, select the title of the course, the final score and the counter of the students. Then put the title of the course on the final quality left on top and the County as your data point.
Rod West
-
Try to understand the cross tab reports.
I'm looking at 3 different examples. I have a question about something I see on 2 examples.
Example 1.
http://2.BP.blogspot.com/_F24IZvIkLOI/SrpSl8JSEBI/AAAAAAAAAlQ/ETt_kB3dIew/S1600-h/IKE.jpg
<? for each group -: / EXPENSE_REPORT/EXPENSE_ITEMS; / DATE? >
<? variable@InContext:G1;current-group()? > <? DATE of? >
Example 2.
http://technology.AMIS.nl/2007/01/30/XML-Publisher-building-a-matrix-report-sqllims/<? for-each-group@section:row;. / SAMPLE_ID? >
<? sort: SAMPLE_ID; ' ascending '; data-type = "text"? >
<? SAMPLE_ID? >
<? variable@InContext:SAM_ID; SAMPLE_ID? >My question is..? variable@InContext: creates a variable but what incontext means?
Sound in the two examples.
Both create variables but and in example 2 explains the variable SAM_ID will hold the sample_id for this group.
My question is why - what is needed?
Thank you
Howard
-is to define a variable 'G1' and him assigning the value of the field Current - group (). The @incontext command maintains the variable located inside the loop... (you can not update but you can simply reference or re - declare)
You can insert a field (BI Publisher menu - field and select a field from your xml file) and then double click on and click on properties of Word-> help add some text and then edit (delete the existing code or modify the code to what it must be)
Thank you
~ KKT ~.
-
Here's a puzzle. The table on the cross tab below should display text values in row 2, column 2 and not a sum. In addition, there are several values for each column, and they need to be under another. For example, let's say that the desired output is as follows:
Industry - 2005 - 2004 - 2003
Society 1-10-30-25
-------------------------20---------50----------0
Company 2 - 12 - 0-15
'0' cells may simply include white, that's all that is needed.
Here's the RTF cross code table tab:
Cell 1.1 {noformat} <? horizontal-break-table: 1? > {noformat}
Cell 1.2 {noformat} <? for-each-group@column:results;. / YEAR? > <? YEAR? > <? end for each group -? > {noformat}
Cell 2.1 {noformat} <? for-each-group: RESULTS; / INDUSTRY? > <? variable@InContext:G1;current-group()? > <? INDUSTRY? > {noformat}
Cell 2, 2 {noformat} <? for each group-@cell://RESULTS;. / YEAR? > <? for - each:current-group()? > <? ($G1[(./YEAR=current()/YEAR)]/SALES)? > <? end foreach? > <? end for each group -? > <? end for each group -? > {noformat}
However, this does not have the expected results. It displays this, which is not correct:
Industry - 2005 - 2004 - 2003
Society 1-10-30-25
-------------------------10---------30---------25
-------------------------10---------0-----------0
Company 2 - 12 - 0-15
-------------------------12---------0----------15
-------------------------12---------0-----------0
The following XML code:
rowset <>
< RESULTS >
The <>Company INDUSTRY 1 < / INDUSTRY >
< YEAR > 2005 < / YEAR >
< > 10 SALES < / SALES >
< / RESULTS >
< RESULTS >
The <>Company INDUSTRY 1 < / INDUSTRY >
< YEAR > 2005 < / YEAR >
< > 20 SALES < / SALES >
< / RESULTS >
< RESULTS >
The <>Company INDUSTRY 1 < / INDUSTRY >
< YEAR > 2004 < / YEAR >
< > 30 SALES < / SALES >
< / RESULTS >
< RESULTS >
The <>Company INDUSTRY 1 < / INDUSTRY >
< YEAR > 2004 < / YEAR >
< SALES > 50 < / SALES >
< / RESULTS >
< RESULTS >
The <>Company INDUSTRY 1 < / INDUSTRY >
< YEAR > 2003 < / YEAR >
< > 25 SALES < / SALES >
< / RESULTS >
< RESULTS >
<>company 2 < / INDUSTRY >
< YEAR > 2005 < / YEAR >
< > 12 SALES < / SALES >
< / RESULTS >
< RESULTS >
<>company 2 < / INDUSTRY >
< YEAR > 2003 < / YEAR >
< > 15 SALES < / SALES >
< / RESULTS >
< / LINES >
Any ideas? Thank you very much!Give you a few points: 0)
-
Cross tab report vertical display?
Is it possible for a cross-tab (or another format of report template RTF) to achieve this?
The only problem with our cross tab report is that the data should be grouped by day. This is the format we want to achieve:
Employee - MON - TUE - sea
John - 08:15 - 08:15 - 11:00
-12:15 PM - 08:15-16:00
-01:15 PM - 08:15-17:00
-17:30 PM - 08:15-19:30
Mary - 10:00 - 08:15 - 10:00
-14:15 PM - 11:15 - 14:15
-15:15 PM - 12: 15 - 15:15
-19:30 PM - 17:15-19:30
In this way, each watch used (John and Mary) time, they started to work and below the time they went on their lunch break below that time back from lunch break and below the time they finished the work.
With a report of the cross we tab get these results:
Employee - Monday - TUES - Wednesday - Thurs
John - 08:15 - 12:15 - 13:15-17:30
Mary - 10:00 - 14:15 15:15 PM - 19:30
The data goes across the row instead of to the bottom. John 12:15 time lunch should appear directly above the time of 08:15 that he begins to work as in the first example.
Suggestions for a report on the cross tab (or any other type of format) to display data like that?
Thank you very much! :)OK, I got it, bit of hacking, and I got the result you wanted... old skool crosstabbing
! http://blogs.Oracle.com/xmlpublisher/images/CTab2.jpg!
The fields are
! http://blogs.Oracle.com/xmlpublisher/images/CTab3.jpg!
He writes for a blog next week...
RTF model available here [http://blogs.oracle.com/xmlpublisher/files/ToughCrossTab.rtf]
Tim
-
possible to encapsulate cross tab on the same page, rather than on the next page?
Hello
I'm working on a report on the cross tab in .rtf. I noticed that when there are more columns that can fit on a page, the prosecution is carried out on a new page. Is it possible to have continued to perform on the next 'line' under the first instead of on the next page?
Thank you
JKIt's here :)
http://winrichman.blogspot.com/2009/05/cross-tab-by-limiting-number-of-colums.html
-
Cross tab with several expandable columns
Hi all
I develop a cross tab report... is my example of xml file
<? XML version = "1.0" encoding = "UTF-8"? >
rowset <>
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > Call - Back-Office < / DD_CODE >
< NOTE_DATE > 12 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > Call - Back-Office < / DD_CODE >
< NOTE_DATE > 11 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > Call - Back-Office < / DD_CODE >
< NOTE_DATE > 14 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > Call - Back-Office < / DD_CODE >
< NOTE_DATE > 112 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > Call - monitoring < / DD_CODE >
< NOTE_DATE > 121 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > Call - monitoring < / DD_CODE >
< NOTE_DATE > 122 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > Call - monitoring < / DD_CODE >
< NOTE_DATE > 131 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > Call - monitoring < / DD_CODE >
< NOTE_DATE > 111 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
Visit Site < DD_CODE > - Back-Office < / DD_CODE >
< NOTE_DATE > 11 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
Visit Site < DD_CODE > - Back-Office < / DD_CODE >
< NOTE_DATE > 143 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
Visit Site < DD_CODE > - Back-Office < / DD_CODE >
< NOTE_DATE > 122 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
Visit Site < DD_CODE > - Back-Office < / DD_CODE >
< NOTE_DATE > 111 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
Visit Site < DD_CODE > - monitoring < / DD_CODE >
< NOTE_DATE > 1432 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
Visit Site < DD_CODE > - monitoring < / DD_CODE >
< NOTE_DATE > 112 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
Visit Site < DD_CODE > - monitoring < / DD_CODE >
< NOTE_DATE > 121 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
Visit Site < DD_CODE > - monitoring < / DD_CODE >
< NOTE_DATE > 123 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > visit - WDE Office < / DD_CODE >
< NOTE_DATE > 123 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > visit - WDE Office < / DD_CODE >
< NOTE_DATE > 1321 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > visit - WDE Office < / DD_CODE >
< NOTE_DATE > 1312 < / NOTE_DATE >
< / ROW >
< ROW >
Product < NAME > < / NAME >
< DATE > 2008 - 05-01 T 00: 00:00.000 - 05:00 < / DATE >
< TYPE_CODE > < / TYPE_CODE >
< MOST_RECENT_NOTE_DATE > 1 < / MOST_RECENT_NOTE_DATE >
< DD_CODE > visit - WDE Office < / DD_CODE >
< NOTE_DATE > 211 < / NOTE_DATE >
< / ROW >
< / LINES >
If I use the cross-tab Wizard... I get the following output...
The figures in each column are dynamic... I might have 2,3,4... (In this case, all are four)... I looked at the link below, but he had static 2 repeat columns... but in my case, the columns of repetition are unknown...-------------Call - Back Office-------Call - Monitoring-------Site Visit - Back Office-------Site Visit -Monitoring-----Visit - WDE Office product 12 121 11 1432 123 but I'm looking for output like... -------------Call - Back Office-----Call - Monitoring------Site Visit - Back Office------Site Visit -Monitoring-------Visit - WDE Office product-------12 11 14 112-----------121 122 131 111----------11 143 122 111------------------1432 112 121 123 ---------123 1321 1312 211
http://winrichman.blogspot.com/2008/09/crosstab-with-multiple-repeating.html
Is is possible to build a cross- like this tab... ?
Thanks in advance...Hello
Email me at colectionaru at gmail dot com
I'll watch your xml and post a solution here.Kind regards
Colectionaru -
SORTING FOR THE FIELD OF COMPUTING IN CROSS TAB REPORT
LIST_G_AUCTION_TITLE >
< G_AUCTION_TITLE >
< BID_NUMBER > 5002 < / BID_NUMBER >
< AUCTION_TITLE > E2E-01 Construction RFQ < / AUCTION_TITLE >
C2631 < ITEM_NUMBER > < / ITEM_NUMBER >
< ITEM_DESCRIPTION > 4G, 000, 000, 0STRUC, X, SPECIAL STRUCTURE < / ITEM_DESCRIPTION >
< ESTIMATED_QTY > 1 < / ESTIMATED_QTY >
LS < UNIT > < / UNIT >
< QUOTE_PRICE > 400 < / QUOTE_PRICE >
< ESTIMATED_QUOTE_PRICE > 400 < / ESTIMATED_QUOTE_PRICE >
< PROVIDER > X - L CONTRACTING < / PROVIDER >
My xml data in this format, I have created a relationship of the cross for ITEM_DESCRIPTION line and SUPPLIER as the column tab and calculated a sum (ESTIMATED_QUOTE_PRICE)
for all ITEM_DESCRIPTION for each PROVIDER in templete. now, I need to sort the data by sum (ESTIMATED_QUOTE_PRICE) from the lowest to the more than left to right, which is the supplier with the lowest sum (ESTIMATED_QUOTE_PRICE) should display first from left to right.
can anyone help thanks in advance.Hi Sandy,
Thought, you would do the rest :)
Neway, sent you an update. -
Cross tab in the SELECT statement?
Hello
The following SQL statement:
SELECT
T.LASTFIRST, C.COURSE_NAME, CC. COURSE_NUMBER, CC. SECTION_NUMBER, CC. EXPRESSION, ST. SEX, COUNT (CC.) STUDENTID) STUDENTCOUNT
TEACHERS T
JOIN THE CC
ON CC. TEACHERID = T.DCID
JOIN THE COURSE C
ON C.COURSE_NUMBER = CC. COURSE_NUMBER
JOIN STUDENTS ST
ON CC. STUDENTID = ST.ID
WHERE CC. SCHOOLID = 100 AND TERMID > = 1900
T.LASTFIRST, C.COURSE_NAME, CC GROUP. COURSE_NUMBER, CC. SECTION_NUMBER, CC. EXPRESSION, ST. BETWEEN THE SEXES
ORDER OF T.LASTFIRST, CC. COURSE_NUMBER, CC. SECTION_NUMBER, CC. EXPRESSION, ST. BETWEEN THE SEXES
Returns the following dataset:
Abram, American history Michael SOC1000 1 a 2 F 7
Abram, American history Michael SOC1000 1 has 2 M 12
Is there a way to make the count gender for each sex, introduce yourself as a column in the SELECT statement so that there is only ONE row returned by course number with as FEMALECOUNT and MALECOUNT column headers?
I tried to use a statement select count nested inside the original SELECT statement but without success.
JeffYou should be able to use a CASE statement for this in collaboration with the County. COUNTY does not indicate that null instances no I have not specified a part to the CASE ELSE (so the default value is NULL).
COUNT(CASE ST.GENDER WHEN 'F' THEN 1 END) as Female_count, COUNT(CASE ST.GENDER WHEN 'M' THEN 1 END) as Male_count,
Note that you need to remove the Gender of your query column.
-
Key value pair relational table - cross tab / pivot out?
I have a Table of KVP and the structure is ID, Key, Value and this is the sample values...
Table with values
ID, Key, Value
TABLE 1, TRUE
1, AGE GROUP, 10
1, TRAVEL, Y
2, TABLE, FALSE
2, AGE GROUP, 20
2, TRAVEL, N
I want to turn it these date like below (output)
ID, STATUS, AGE GROUP, TRAVEL
1, TRUE, 10, Y
2, FALSE, 20 N
I read on analysis crossroads/pivot - but not able to make a query that can give me the output above. The structure of the table cannot be changed...! My bad.
Is it possible in sql, to do my output to look like above?It is possible if you know all the possible values for the KEY:
with t as ( select 1 id,'STATUS' key,'TRUE' val from dual union all select 1,'AGE GROUP','10' from dual union all select 1,'TRAVEL','Y' from dual union all select 2,'STATUS','FALSE' from dual union all select 2,'AGE GROUP','20' from dual union all select 2,'TRAVEL','N' from dual ) select id, max(case key when 'STATUS' then val end) status, max(case key when 'AGE' then val end) age, max(case key when 'AGE GROUP' then val end) "AGE GROUP", max(case key when 'TRAVEL' then val end) travel from t group by id / ID STATUS AGE AGE GROUP TRAVEL ---------- ------ ----- --------- ------ 1 TRUE 10 Y 2 FALSE 20 N SQL>
If you are on 11g, you can use the PIVOT, but again, he must know the columns resulting from the outset.
Another thing, you could do is to return a list CSV key of all the values in a column using STRAGG (or LISTAGG if you are on 11.2), hierarchical queries, XML or WM_CONCAT without papers.
SY.
-
Cross tab / filter the lines of pivot
Hello guys,.
It's been a day and I can't understand how to filter PivotTables using RTF Model Designer in word.
The web-page-builder has a filter function, but the RTF an it is missing from the menu. So I think there must be some scripts.
I had up to now:
<? If: cartype = 4? >
<? end if? >
but I don't know where to put it, I tried to place on each item but... no luck.
Someone there done that before and can share the secret?Hi BIPuser,
Finally, it worked. I added the following to the for each element.----------
---------------------------
-
Filter a cross-tab that is nested in a group
Hi all -
I have a crosstab report that is nested in a group on my rtf model. I would the crosstab filter so that only the lines that relate to the current group are included in the crosstab. The crosstab and the Group share a common data element:
Group: <? for-each-group: ROW; *. / SALES_DISTRICT *? >
Nested crosstab: <? crosstab:c835; "' LINE '; "SALES_REGION {, o = a, t = t}, SALES_GROUP {, o = a, t = t}, * SALES_DISTRICT {, o = a, t = t} * '; "Managed_ind {, o = a, t = t} '; "' Avg_Mthly_Adj_Sales_09, Avg_Mthly_Adj_Sales_10, Avg_Mthly_Adj_Sales_Fcst_11; "' sum '? >
Can someone help with the syntax that will allow me to implement this filter?
Thank you
Mac
Edited by: macearl on July 16, 2010 09:04Group: -hope that is outside the table
Nested crosstab:
Maybe you are looking for
-
Mac mini 2010 change or difficulty?
I have a mac mini 2010, put in extra RAM. During the ages erase and reinstall Captain el OS because the spinning wheel of dreaded. Whenever I try to start it, it takes forever and the spinning wheel occurs. I have to keep doing a STROLLER and it is
-
When I open a document in my mail from GoDaddy that I accessed through Firefox (Mozilla), I have to open it; can do small; then expand until I can scroll down. Is it possible to change this? My computer is HP Envy. Thank you very much!
-
HP laptop: computer startup
I turned on my laptop and it says no bootable device insert disk
-
An error occurred when DNS was questioned about the resource record (SRV) service location used to locate a domain controller Active Directory (AD DC) for the domain 'HAMI. LOCAL ". The error was: "an existing connection was to be closed by the remot
-
CPU utilization of WS - C3750X - 48PF - S
First of all, I bought switches with Ref. WS-C3750X-48P with the following IOS c3750e-universalk9 - mz.150 - 1.SE1 & license feature IOS to work as ipservice. Symptoms: (1) - during the delivery of the switches in the stacking mode (connecting the sw