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:
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);
With similar results to: -.
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
This is the Group of periods which is I don't know how to do.

Thank you & best regards,

Andrew

Hello

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

Tags: Database

Similar Questions

  • 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...
    -------------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
    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...
    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

  • Cross tab report with a Twist

    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 using sql

    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 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

  • How can I restore my tabs and groups of tabs after a update to version 36.0?

    I work with many tabs when I use Firefox. I keep classified in groups of tabs, which helps to separate the different children to work I do and interests I have. I have been using this environment for years. When I started my job today, Firefox updated to v36.0, and noted the following behaviors:

    1. There is only one group of tabs when you try to display tabs at Panorama, as opposed to a dozen groups;

    2. normally if the hidden tabs (tabs in the same group as the startup group, and not the default page) downloading of content to what the user clicks on, icon, if any, and the name of the page will show on the tab currently, the tabs display 'New tab' and no icon. It seems, however, the number of tabs that exist across all groups of tabs, but are now ghosts this default value, a group of tabs. I must add, however, I do not count the number of tabs, so I can't be exactly. When you click on it, there is just a blank page. It is so strange that Firefox knows they are there but cannot simply attach the address.

    I tried to restore the following files from my backup of Windows Home Server to the folder AppData\Roaming\Mozilla\Firefox\Profiles\ .default < gobbletygook >:

    1. in the sessionstore-backups folder, I replaced the files previous.js, recovery.bak and recovery.js (not all of the upgrade ~) with the files yesterday and the day before yesterday.

    When that did nothing, I replaced

    2 sessionCheckpoints.json

    I do not see any file with a recent date that seems to be the one that I have to restore. I should add that I don't see hidden files. I thought about the restoration of the whole of the batch, but didn't know how it would affect the program v36.0 and the profile on 35.0.1 files.

    I have deadlines this week and must immediately restore my environment in order to make these possible. I have no address list on my Web pages to work in IE or other. Any help would be much appreciated.

    On a second note, I had been wondering recently if this tab group environment is an appropriate way to maintain my work environment. Sometimes, during the opening of Panorama, I would get an error saying a script takes too much time, but if I clicked on continue, it would display the groups in a few seconds. I considered bringing it in bookmarks, but it would be tedious and more difficult to access and open several tabs. Initially, I tried tabs groups thinking it was just a matter of maintaining a table of addresses (in tabs) with a name or an ID of tab group. How that might go wrong? Well, there, so it is obviously more complicated than that, and I did not know that upgrades would affect the data of a personal nature. That I should abandon the use of tab groups?

    With the help of information from the user, ptressel, in a post here on the existence of sessionstore.js when version 33 was released, I could easily get my tabs and groups of tabs as follows:

    1. close Firefox and, perhaps, wait a few seconds (30 years?) for any final closing of files;
    2. Check if you have a sessionstore.js file in your profile folder, named as I documented in my original post above.
    3. If this is not timestamped before the discovery of your problem, open the sessionstore-backups folder.
    4. Check if the recovery.js file is properly stamped and, if not, the recovery.bak.
    5. At this point, you are likely to find that none of them is before your problem occurring. If so, open your backups from this folder and go through steps 2 to 4 to find a file before your problem occurring.
    6. When you find a file, copy it to the root of your current profile folder and name it, "sessionstore.js.
    7. Open Firefox. Mine opened upwards as you wish.

    It is a solution for Windows. Sorry I can't comment on other platforms, but I'd bet it's just a copy of file and change of name, it is likely even.

    For Windows users, you can find you must sign out and sign in as administrator in order to access backups. You must not logoff your standard account, but do have Firefox closed as described above.

    Hope that helps.

  • Is it possible to save the current tabs and groups so that they can be recharged at any time?

    My Firefox crashes sometimes, and when I start it up again, my groups and tabs that I had are lost, so I need to recreate my history window. Is there a way I can save the groups that I have with the tabs on the inside so that I can retrieve them at a later date.
    "I say that Firefox does not save the whenever I close the browser, so I'm güssing there a file somewhere that contains this information, if I know how is called this file I could save it on my regular schedule and retrieve them if I had to, of course the best solution would be to have a ' save the groups ' & 'Support groups' in the menu.

    Thanks in advance
    DayoJ

    (PIN) App tabs and groups of tabs (Panorama) are stored in session data in the sessionstore.js file in the Firefox profile folder.

    You can use this button to go to the Firefox profile folder currently in use:

  • Research Protect deleted all my tabs and groups of Firefox

    I had about 200 tabs grouped together in about 30 groups of 31.0 Firefox (latest version). The Group appeared when I clicked on the icon to the left of the button "minimize" or press CTRL + SHIFT + E. It is called "your Firefox tabs - group". I also use Xmarks, but I have disabled Synchronization tab recently.

    Generally all the tabs and their groups have been saved when I closed Firefox. Today I opened Firefox and all tabs and groups disappeared! Instead, it opens some search engine called Trovi (www.trovi.com) with "bing results. Its the same in Chrome, Opera and IE.

    My OS is Windows 8.1 update 1 with all updates installed. My antivirus is Avast! with all updates installed. There was some malware installed of course, but I'm not awake me. I ran a 'full system test' in Avast! latest updates, which is the deeper analysis that I know (without my laptop HP ProBook 4730 s restaring). No viruses were found.

    I'm suspecting a program called 'Research Protect' version 2.16.10.61 'Client Connect Ltd. It was installed with PowerISO 6.0 x 64.

    I tried to run the system restore, but it seems that all the restore points I ever created are now deleted! I discovered this by opening the system properties-> system-> system restore Protection. However, 'Protection' is 'On' for my system disk.

    How can I restore my tabs and groups? It is extremely important for me.

    Accidentally, I posted my question twice - my apologies. I marked this as resolved and will continue to ask for help on the other.

    https://support.Mozilla.org/Ta/questions/1014087

    Thank you!

  • tabs and groups of tabs are lost

    Closing Firefox and then restarting him, invariably all my tab groups seem to have lost their legs. Reopening of groups of Eve extended or closed (using the Group Manager add-on tab) will not help.

    It is not happened on my previous install but have since upgraded to Kubuntu 14.04 and Firefox 29 (to be precise Firefox to canonical 1.0), I keep losing my tabs and groups of tabs.

    Don't know what mistake I make.

    In case you use "clear history of Firefox closing:

    • do not erase browsing history

    Note that compensation "Preferences of Site" clears all exceptions for cookies, images, pop-up windows, installation of software, passwords, and other specific data from Web site.

    You can check for problems with the sessionstore.js and sessionstore.bak files in the profile folder of Firefox that store session data.

    Rename (or delete) the sessionstore.js file and possible sessionstore-# .js files with a number and sessionstore.bak in the Firefox profile folder.

    Delete sessionstore.js will cause App Tabs and groups of tabs open and closed tabs (back) to get lost and you will have to re-create them (take note or bookmarks if possible).

  • Every time Firefox opens, I get new tab, with my desired as a tab page I click on get to. How to get back to how it was in previous versions?

    After updating to the latest version of Firefox, when it opens I get two tabs, and one that appears on my screen is new tab with my homepage on the other, which requires that I click on it to go. Also, when I click on a link, the same thing happens, a new tab page comes up, with what I clicked on as another tab I have to click to get to. It's actually quite boring and inconvenient. How to get back to the way it was, so that when I run Firefox it opens on my homepage, and when a new page opens, I see the content of the link I clicked on? This new and improved IMO is really new and worse.

    A further extension could have snuck in. These can be bundled with other software you may have installed recently.

    Try turning off all non-essential or unrecognized extensions on page modules. Either:

    • CTRL + SHIFT + a
    • Firefox orange (or the Tools menu) button > Add ons

    In the left column, click Extensions. Then, when in doubt, turn off. (Or so completely junk, delete).

    Typically, a link will appear above at least an extension disabled to restart Firefox. You can complete your work on the tab and click one of the links in the last step.

    That get rid of the extra tab?

    Note: I also suggest to visit the Control Panel, uninstall a program and by clicking on the column heading "installed on". This should bring the most recent additions at the top and group by install date so that you can examine the software may have unexpected how have been installed.

  • restoration of a restore on another tab get group of tabs not in the current session

    I already opened a tab and want to add a bit of session manager
    When I select session Manager session, I just want to add a few session tab (not all tab) with "add to current windows."
    but the tab not showing do not in my session active... when I check 'group of tabs', I found the tab add this session in another group of tabs in my current group...
    That's happened?

    Extensions. {1280606b-2510-4fe0-97ef-9b5a22eafe30} .do_not_fix_tabgroups - set to true to prevent Session Manager tries to correct groups of tabs when restoring sessions. The default value is false.

  • Cannot open my tabs to group.

    I saw a similar topic but the answers do not help. Previously, I do not have the session Manager installed, so I am unable to restore to an earlier date. When I open Firefox I script my computer will not meet the and the message I get is:

    script: resources: //app/modules/tabview/utils.jsm:617

    Would be grateful for answers to how do to solve this problem, I use this feature a lot.

    Kind regards

    You can check for problems with the sessionstore.js and sessionstore.bak files in the profile folder of Firefox that store session data.

    Delete the sessionstore.js file possible sessionstore-# .js files with a number and sessionstore.bak in the Firefox profile folder.

    Delete sessionstore.js will cause App Tabs and groups of tabs open and closed tabs (back) to get lost and you will have to re-create them (take note or bookmarks if possible).

  • I updated FF to 15.0.1; now there is no new tabs boxes, and I can't remove a tab with scroll wheel.

    I use Windows XP.
    Then, he used to be a small square next to the last tab box open that I could click to open a new tab. Now, I can just open a new tab if I double click on a space empty next to the last open tab.
    And I used to be able to open a group of tabs, to do what I had to do and then click Center mouse scroll to the bottom of the line to delete what I have is no longer necessary. Now, the only way I can close tabs is to use the x on the right side of the tab I'm currently. But, sometimes it does not work...
    Nothing has changed about how I put FF in place - just the update.

    You can open a new tab with Ctrl-t. You should be able to find the new tab button in the Customize window toolbar. You can replace it. If the Middle-click to remove is no longer a tab, you can use Ctrl-left click.

  • Where are my saved tabs Firefox groups?

    I had a lot of tabs organized in groups to read later... I installed a few Add-ons that some of them had to do with tabs (Xmarks, FoxTab)...
    After restarting Firefox, my groups and tabs are all lost!
    Please help me... I have a sort of memory lost feelings after this mess!

    SOLVED;
    Thank God, I have restored all my tabs...
    and thank you too @cor-el
    In case of problems with the 'session restore '.
    I summarize it:
    1 - Go to help-> troubleshooting information
    2 - Click Open "containing the file.
    3 * [IMPORTANT] * CLOSE FIREFOX NOW
    4-cup sessionstore - 1.js (or any other number following) and paste it on the desktop
    5 rename sessionstore - 1.js in desktop to sessionstore.js
    6. * [IMPORTANT] * DELETE sessionstore.bak
    7. move sessionstore.js located in the office and place it in the folder "container".
    8 - choose move and replace (in win7)
    9 - start Firefox and have fun with your session restored!

    E-mail: [email protected]

    (PIN) App tabs and groups of tabs (Panorama) are stored in session data [1] in the sessionstore.js file [2] in the Firefox profile folder [3].

    Make sure that you do not use "Clear recent history" to clear the 'browsing history' when Firefox is closed because who wins and prevent Firefox tabs from the previous session.

    It is also possible to use the "Show my windows and tabs from last time" parameter, which is generally a more reliable way to restore the session data.

  • Trying to understand what he in @incontext: average when you create a variable in a cross tab report.

    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 ~.

Maybe you are looking for