Need a cross tab query nickname
Do not know how to proceed. I have a table with content thatEmpID
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/12
Hello
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
Tags: Database
Similar Questions
-
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
-
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 ~.
-
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
-
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)
-
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
-
I used Google to my home page. Google went to Google +. I'm not interested. When I opened my Google home page, empty of course, on my HP laptop, Win7, I do not see the top left orange tab that allows me to do "good things". On top of my office, Win XP, I can still see the orange tab. Why is it different? I really need this Orange tab a top left. This is the portal of many features that I use. Thank you!
Please ensure that you have not enabled the menu bar.
This can be done:- Right-click in an empty tab bar area
- Bar menu uncheck the menu drop-down
You are referring to the Firefox button, correct?
-
Hi I have just signed up for the Apple's music and I forgot to cancel my game from itunes (it is no longer needed) who crossed just automatically - how to cancel the game and can get a refund?
To stop renewing, login to your account (for example by tapping your id settings > iTunes & App Store on your iPad, or by clicking on your name / icon to the top right of the iTunes on iTunes on your computer screen), and go to the iTunes in the cloud Section - see to halfway down this page: subscribe to iTunes game - Apple Support
In terms of refund, try to contact iTunes Support and see if this will change (purchases are considered final), either via http://reportaproblem.apple.com or http://www.apple.com/support/itunes/contact/
-
Oracle Version: 11.2.0.2.0
I need assistance with the output of the query. Here is the table.
With Tbl_Nm as
(
Select 'ABC1' SYSTEM_ID, REGION 'US', 'CHI' SUB_REGION 4000 BALANCE, to_date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') LAST_UPD_TIME, 'A' FLAG of union double all the
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select * from tbl_nm
I need the output below.
PQR2 UK MC 2600 1 OCTOBER 2012 04:45
ABC1 US NY 3500 October 1, 2012 06:45
LMN3 UK BT 2500 November 1, 2012 07:45
The need the disc according to this system_id flagged as "A". But if the last disc of 'd' then it must show that the amount, but the file should be displayed in 'A '.
I've tried a few and got stuck. Help, please. Not able to get a balance '.
This question is a bit similar to needing help with a query result
With Tbl_Nm as
(
Select 'ABC1' System_Id, region 'US', 'CHI' Sub_Region, 4000 balance, To_Date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') Last_Upd_Time, 'A' flag of double Union All
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select System_Id, region, Sub_Region, Balance, Last_Upd_Time of Tbl_Nm T1
where t1. Last_Upd_Time = (select max (Last_Upd_Time) in the Tbl_Nm T2 where T1.) SYSTEM_ID = T2. SYSTEM_ID)
So maybe you'd then
ORDER BY DECODE(flag,'D',9,1) ASC...
to get the Ds at the end of the list.
or
ORDER BY CASE WHAT flag = has ' (your other filters) AND then 9 or 1 end CSA,...
HTH
-
Need to the tab of each document (Word or PDF) being converted/combined into a single PDF file. Only have an online account. Is this possible online?
Hi pjj,.
When you open the Bookmarks pane (the second icon from the top in the column the leftmost in Acrobat), you will see a bookmark for each file that has been attached to create the PDF. If you have created the combined file from Acrobat.com, however, file names are changed, it won't be as easy to say what are the components. If you create the file in Acrobat, then bookmarks retain the name of the original file, so your customer will be able to tell at a glance if everything was included.
Best,
Sara
-
When we need to use a query variable and how to use it?
Hello
When we create a line of dashboard, we set the variable, there are two types: variable presentation and application.
I'm confuse when we need to use a query variable and how to use it?
Thank you
AnneHello
The variable 'demand' can be used if you want to use session related information specific to you.See below a:
http://gerardnico.com/wiki/dat/OBIEE/logical_sql/obiee_set_request_variable_dashboard_promptFYI... example of
for the example query variable (a good post Nico)http://gerardnico.com/wiki/dat/OBIEE/set_variable
for the variable of presentation with example
http://gerardnico.com/wiki/dat/OBIEE/presentation_variable
Thank you
Deva
-
Hi gurus
need help with this query,
I want to display the records in the table emp
I want just the recordsSQL> Select Deptno,sal,sal/SUMSAL Percent,rn 2 From ( Select emp.*,Sum(Sal) Over() "SUMSAL",Row_number() Over(Order by sal Desc) rn 3 From emp 4 ) 5 / EMPNO DEPTNO SAL PERCENT RN --------- ---------- ---------- ---------- ---------- 7839 10 5000 .172265289 1 7902 20 3000 .103359173 2 7788 20 3000 .103359173 3 7566 20 2975 .102497847 4 7698 30 2850 .098191214 5 7782 10 2450 .084409991 6 7499 30 1600 .055124892 7 7844 30 1500 .051679587 8 7934 10 1300 .044788975 9 7521 30 1250 .043066322 10 7654 30 1250 .043066322 11 7876 20 1100 .037898363 12 7900 30 950 .032730405 13 7369 20 800 .027562446 14 14 rows selected.
Thank youEMPNO DEPTNO SAL PERCENT RN ---------- ---------- ---------- ---------- ---------- 7839 10 5000 .172265289 1 7902 20 3000 .103359173 2 7788 20 3000 .103359173 3 7566 20 2975 .102497847 4 7698 30 2850 .098191214 5 with sum (Percent) of remaing records..... Others .420327304
Published by: SeenuGuddu on February 27, 2011 03:39with a as ( Select Empno, Deptno ,sal, sal/SUMSAL Percent, case when rn<=5 then rn else null end rnm From (Select emp.*, Sum(Sal) Over() "SUMSAL", Row_number() Over(Order by sal Desc) rn From emp) ) select case when max(rnm) is not null then to_char(max(empno)) else 'Others:' end empno, case when max(rnm) is not null then max(deptno) else null end deptno, case when max(rnm) is not null then max(sal) else null end sal, to_char(sum(percent), '90.99') percent, max(rnm) rn from a group by rnm order by rnm
EMPNO DEPTNO SAL PERCENT RN ---------------------------------------- ---------------------- ---------------------- ------- ---------------------- 7839 10 5000 0.17 1 7902 20 3000 0.10 2 7788 20 3000 0.10 3 7566 20 2975 0.10 4 7698 30 2850 0.10 5 Others: 0.42 6 rows selected
-
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
Maybe you are looking for
-
My Satellite M40X: DVD Rom has had serious problem
Dear friends, my laptop worked for 3 months without any problem.these days when I put a CD in DVD rom is not recognized and a error message on the screen that says that no cd is in the drive.could would be a software problem or it's definitely a hard
-
Hey people, my first time here. My question is this: I recently started a company, and I would like to open a Skype account for purposes of allowing my tech savy customer contact via Skype. I am also an avid player and use Skype constantly. So I was
-
Stop: error message 0 x 00000024 when try to start the Windows XP computer.
Original title: does not start How to fix laptop computer that will not start. It starts with a blue screen with the following information. :- Stop: 0 x 00000024 (0 x 00190203, 0x86F4B2B8, 0XC0000102, 0x00000000)
-
HP Pavilion G6-1116so, Window XP drivers help
Hi all! My name is Damien, I was born in Iceland, but I lived in Sweden since I was 3 years old. I am currently 19 years old and student I hope to become an Automation engineer. I bought a HP Pavilion G6-1116so to use at the school, which was a very
-
Windows 7 is suddenly not authentic?
They are DCXK4