Group By Multiple Columns

I am using the BI plug-in to try and create a multi-column grouped report similar to below:
Emp Name Emp ID Dept Job
Bob_______100____Job1
_________________Job2
_________________Job3
Tom______200____Job1
I use the table form wizard, move all my nodes over and choose to group by Emp Name on my Rowset. I then click on Emp Name and choose to group by Emp Id. I then say ok to create output (choosing table). IS this how you are supposed to create multi-grouped report?

Ok XML on the bottom.
The STUDENT_ID and STUDENT NAME are the grouped fields.
Layout would be a table looking like this:
F STUDENT_ID STUDENT_NAME RELATION_DESC CONTACT_NAME ADDRESS_LINE1 PHONE EMERGENCY_PHONE
Total Students Printed: ttt
E
Thanks for your help.
you can email me template you create at: [email protected]
<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<ROWSET1>
<ROWSET1_ROW>
<STUDENT_NAME_LABEL>Student</STUDENT_NAME_LABEL>
<STUDENT_ID_LABEL>ID#</STUDENT_ID_LABEL>
</ROWSET1_ROW>
</ROWSET1>
<ROWSET2>
<ROWSET2_ROW>
<STUDENT_NAME>Adams, Angela Marie </STUDENT_NAME>
<STUDENT_ID>CHS0001</STUDENT_ID>
<CONTACT_RELATION>A</CONTACT_RELATION>
<CONTACT_REL_DESC>Aunt</CONTACT_REL_DESC>
<CONTACT_NAME>Ms. Margaret Mary Dale </CONTACT_NAME>
<ADDRESS_LINE1>300 Main Street </ADDRESS_LINE1>
<ADDRESS_LINE2>Freehold, NJ 07728</ADDRESS_LINE2>
<ADDRESS_LINE3></ADDRESS_LINE3>
<PHONE>(732) 555-4354</PHONE>
<PHONE_DESCRIPTION></PHONE_DESCRIPTION>
<EMERGENCY_PHONE></EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION></EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
<ROWSET2_ROW>
<STUDENT_NAME>Adams, Angela Marie </STUDENT_NAME>
<STUDENT_ID>CHS0001</STUDENT_ID>
<CONTACT_RELATION>GF</CONTACT_RELATION>
<CONTACT_REL_DESC>Grandfather</CONTACT_REL_DESC>
<CONTACT_NAME>Mr. George Adams </CONTACT_NAME>
<ADDRESS_LINE1>132 Green Glade Drive </ADDRESS_LINE1>
<ADDRESS_LINE2>Century City, NJ 09009</ADDRESS_LINE2>
<ADDRESS_LINE3></ADDRESS_LINE3>
<PHONE>(732) 555-1890</PHONE>
<PHONE_DESCRIPTION>Home</PHONE_DESCRIPTION>
<EMERGENCY_PHONE></EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION></EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
<ROWSET2_ROW>
<STUDENT_NAME>Adams, Angela Marie </STUDENT_NAME>
<STUDENT_ID>CHS0001</STUDENT_ID>
<CONTACT_RELATION>GM</CONTACT_RELATION>
<CONTACT_REL_DESC>Grandmother</CONTACT_REL_DESC>
<CONTACT_NAME>Mrs. Nancy Dale </CONTACT_NAME>
<ADDRESS_LINE1>1402 Winding Way </ADDRESS_LINE1>
<ADDRESS_LINE2>Century City, NJ 09009</ADDRESS_LINE2>
<ADDRESS_LINE3></ADDRESS_LINE3>
<PHONE>(732) 555-9786</PHONE>
<PHONE_DESCRIPTION></PHONE_DESCRIPTION>
<EMERGENCY_PHONE></EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION></EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
<ROWSET2_ROW>
<STUDENT_NAME>Adams, Angela Marie </STUDENT_NAME>
<STUDENT_ID>CHS0001</STUDENT_ID>
<CONTACT_RELATION>P</CONTACT_RELATION>
<CONTACT_REL_DESC>Parents</CONTACT_REL_DESC>
<CONTACT_NAME>Mr. &amp; Mrs. Frank and Marie Adams </CONTACT_NAME>
<ADDRESS_LINE1>1402 Winding Way </ADDRESS_LINE1>
<ADDRESS_LINE2>Century City, NJ 09009</ADDRESS_LINE2>
<ADDRESS_LINE3></ADDRESS_LINE3>
<PHONE>(732) 555-1515</PHONE>
<PHONE_DESCRIPTION>Home</PHONE_DESCRIPTION>
<EMERGENCY_PHONE>(732) 555-1890</EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION>Grandparent's home</EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
<ROWSET2_ROW>
<STUDENT_NAME>Kopacko, Christopher </STUDENT_NAME>
<STUDENT_ID>700</STUDENT_ID>
<CONTACT_RELATION>F</CONTACT_RELATION>
<CONTACT_REL_DESC>Father</CONTACT_REL_DESC>
<CONTACT_NAME>Mr. George Adams </CONTACT_NAME>
<ADDRESS_LINE1>132 Green Glade Drive </ADDRESS_LINE1>
<ADDRESS_LINE2>Century City, NJ 09009</ADDRESS_LINE2>
<ADDRESS_LINE3></ADDRESS_LINE3>
<PHONE>(732) 555-1890</PHONE>
<PHONE_DESCRIPTION>Home</PHONE_DESCRIPTION>
<EMERGENCY_PHONE></EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION></EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
<ROWSET2_ROW>
<STUDENT_NAME>LaMantia, Andrew </STUDENT_NAME>
<STUDENT_ID>600</STUDENT_ID>
<CONTACT_RELATION>P</CONTACT_RELATION>
<CONTACT_REL_DESC>Parents</CONTACT_REL_DESC>
<CONTACT_NAME>Mr Christopher Kopacko Sr.</CONTACT_NAME>
<ADDRESS_LINE1>176 Colonial Dr </ADDRESS_LINE1>
<ADDRESS_LINE2>Lakewood, NJ 08701</ADDRESS_LINE2>
<ADDRESS_LINE3></ADDRESS_LINE3>
<PHONE>(732) 999-9999</PHONE>
<PHONE_DESCRIPTION></PHONE_DESCRIPTION>
<EMERGENCY_PHONE></EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION></EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
<ROWSET2_ROW>
<STUDENT_NAME>LaMantia, Andrew </STUDENT_NAME>
<STUDENT_ID>600</STUDENT_ID>
<CONTACT_RELATION>U</CONTACT_RELATION>
<CONTACT_REL_DESC>Uncle</CONTACT_REL_DESC>
<CONTACT_NAME>Mr Anthony LaMantia Ph D</CONTACT_NAME>
<ADDRESS_LINE1>45 qqqqq ss zLevi Street </ADDRESS_LINE1>
<ADDRESS_LINE2>wfwvwvwAERVWRV</ADDRESS_LINE2>
<ADDRESS_LINE3>Freehold, NJ 07728-2222</ADDRESS_LINE3>
<PHONE>(732) 541-2254</PHONE>
<PHONE_DESCRIPTION></PHONE_DESCRIPTION>
<EMERGENCY_PHONE>(732) 654-1111</EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION></EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
<ROWSET2_ROW>
<STUDENT_NAME>Magan, Bob Tom </STUDENT_NAME>
<STUDENT_ID>100</STUDENT_ID>
<CONTACT_RELATION>P</CONTACT_RELATION>
<CONTACT_REL_DESC>Parents</CONTACT_REL_DESC>
<CONTACT_NAME>Rich Magan </CONTACT_NAME>
<ADDRESS_LINE1>3 NW Maple Knoll Lane </ADDRESS_LINE1>
<ADDRESS_LINE2>Manalapan, NJ 07726</ADDRESS_LINE2>
<ADDRESS_LINE3></ADDRESS_LINE3>
<PHONE>(732) 363-9311</PHONE>
<PHONE_DESCRIPTION></PHONE_DESCRIPTION>
<EMERGENCY_PHONE></EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION></EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
<ROWSET2_ROW>
<STUDENT_NAME>Magan, Bob Tom </STUDENT_NAME>
<STUDENT_ID>100</STUDENT_ID>
<CONTACT_RELATION>U</CONTACT_RELATION>
<CONTACT_REL_DESC>Uncle</CONTACT_REL_DESC>
<CONTACT_NAME>Mr. Bernard Coster </CONTACT_NAME>
<ADDRESS_LINE1>888 zMaple Ave </ADDRESS_LINE1>
<ADDRESS_LINE2>Lakewood, NJ 08701</ADDRESS_LINE2>
<ADDRESS_LINE3></ADDRESS_LINE3>
<PHONE>(732) 363-1234</PHONE>
<PHONE_DESCRIPTION></PHONE_DESCRIPTION>
<EMERGENCY_PHONE></EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION></EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
<ROWSET2_ROW>
<STUDENT_NAME>Reilly, Amy Michelle </STUDENT_NAME>
<STUDENT_ID>200</STUDENT_ID>
<CONTACT_RELATION>P</CONTACT_RELATION>
<CONTACT_REL_DESC>Parents</CONTACT_REL_DESC>
<CONTACT_NAME>Joseph Reilly </CONTACT_NAME>
<ADDRESS_LINE1>546874 zElf Lane </ADDRESS_LINE1>
<ADDRESS_LINE2>Toms River, NJ 08753</ADDRESS_LINE2>
<ADDRESS_LINE3></ADDRESS_LINE3>
<PHONE>(732) 548-9635</PHONE>
<PHONE_DESCRIPTION></PHONE_DESCRIPTION>
<EMERGENCY_PHONE>(732) 548-9654</EMERGENCY_PHONE>
<EMERGENCY_DESCRIPTION></EMERGENCY_DESCRIPTION>
</ROWSET2_ROW>
</ROWSET2>
</DATA>

Similar Messages

  • Selectively Format Groups with Multiple Columns

    I have a bit of an obscure task I've been trying to hammer out to no avail.  I've searched quite a bit but can't seem to find anyone else who has attempted this.  I have two group by statements, one is a category and the other is a rank.  What I'm trying to do is organize the report so that there are category rows and below each category row is a set of columns for each rank with their associated values as such:
    category1
    rank1     rank2     rank3     rank4
    value1   value1    value1   value1
    value2   value2    value2   value2
    category2
    rank1     rank2     rank3
    value1   value1    value1
    value2   value2    value2
    I've tried using details>Section Expert>>Layout>Format Groups with multiple column.  Unfortunately, this applies to both groups putting the categories into columns instead of rows, making a mess.  Does anyone know of a way to selectively put groups into columns and ensure alignment?  In the above example the user would be able to compare rank values from multiple categories since they all line up.  Any help with this would be very much appreciated.

    Hi,
    Have you tried using a crosstab? Give this a shot:
    1) Group the report on Category
    2) Create a new group header section. Group Header b
    3) Place a crosstab in this section
    4) The columns would be the Rank field, I'm not sure about what you would like to show in the rows
    5) The summarized field would be the Value field ofcourse
    Let me know how this goes.
    -Abhilash

  • Groups into Multiple Columns

    Post Author: Donamese
    CA Forum: General
    I am trying to create a report that is split between 3 companies and all states using a distinct count of individuals (as there are duplicates in the data pool).  I would like the report to look like:
    State             Company 1                Company 2                 Company 3
    AL                       0                                 16                           5
    AR                      3                                  9                             4
    AZ                       5                                 0                              7
    Currently I can only get it to list vertical like:
    Company 1
    AL       0
    AR      3
    AZ       5
    Company 2
    AL     16
    etc....
    I am unable to get the formating of multiple columns with the grouping.  Is it possible?  And if

    Post Author: rookie10
    CA Forum: General
    Try inserting a Cross Tab in the Report or page header. Its pretty much like a pivot table.
    Use State as the Row, Company as the Column, Individuals as Summarized field using Distinct Count as the summary type.
    In customized style part of the cross tab you can hide some of the totals and such to get pretty close to the report above - supress subtotals and such.
    Hope this works for you. I was pretty excited when I found this feature in Crystal.
    Rookie10

  • Group by multiple columns problem

    I am having some problems with my query. For example:
    SELECT STUDENTNUMBER FROM REGISTRATION
    WHERE TERM='A1' AND YEAR=2008
    GROUP BY STUDENTNUMBER
    HAVING COUNT( COURSECODE) = 1;
    which returns:
    STUDENTNUMBER
    123456
    789012
    6 rows selected
    Which is ok, but the problem is i want to list out not only studentnumber but also the coursecode,year and the term of students. But if i do this:
    SELECT STUDENTNUMBER,COURSECODE,YEAR,TERM,
    FROM REGISTRATION WHERE TERM='A1'AND YEAR=2008
    GROUP BY (STUDENTNUMBER,COURSECODE,YEAR,TERM)
    HAVING COUNT( COURSECODE) = 1;
    i got 50+ records in which most of them are duplicates!. To put it shortly i want the 6 records but with the coursecode,year,studentnumber and term listed. is there a workaround for this?

    Thanks everyone for your suggestion!
    I end up using Arun's query but modify it slightly to this:
    SELECT STUDENTNUMBER,COURSECODE,YEAR,TERM
    FROM REGISTRATION WHERE STUDENTNUM IN(
    SELECT STUDENTNUMBER FROM REGISTRATION
    WHERE TERM='A1' AND YEAR=2008
    GROUP BY STUDENTNUMBER
    HAVING COUNT(COURSECODE) = 1) AND TERM='A1' AND YEAR=2008;
    Using the multiple set functions would also yields the same result.Anyway i would post the create table statements and insert statements for everyone's references.
    CREATE TABLE REGISTRATION(
         CourseCode     VARCHAR(15)     NOT NULL     ,
         Year          NUMBER(4)     NOT NULL     ,
         Term          VARCHAR(5)     NOT NULL     ,
         StudentNumber     NUMBER(12)     NOT NULL     ,
         Lecturer          NUMBER(12)     NOT NULL     ,
         Grade          NUMBER(5,2)               ,
         CONSTRAINT REGISTRATION_PKEY PRIMARY KEY(CourseCode, Year, Term, StudentNumber, Lecturer),
         CONSTRAINT REGISTRATION_FKEY1 FOREIGN KEY(CourseCode) REFERENCES COURSE(CourseCode),
         CONSTRAINT REGISTRATION_FKEY2 FOREIGN KEY(StudentNum) REFERENCES STUDENT(StudentNumber),
         CONSTRAINT REGISTRATION_FKEY3 FOREIGN KEY(Lecturer) REFERENCES ACADSTAFF(StaffNum)
    Insert statements:
    INSERT INTO REGISTRATION VALUES('CSE235',2008,'A1',1292601,2001,null);
    INSERT INTO REGISTRATION VALUES('CSE235',2008,'A2',8290012,2001,null);
    INSERT INTO REGISTRATION VALUES('CSE235',2008,'A2',7246935,2002,null);
    I want to list the student number, coursecode, year and term of students who registers for only one course in term "A1" in 2008.The result:
    STUDENTNUM COURSECODE YEAR TERM
    3000911 CSE101 2008 A1
    3335010 CSE101 2008 A1
    3011724 CSE101 2008 A1
    8754117 CSE101 2008 A1
    1032858 CSE101 2008 A1
    3292880 CSE101 2008 A1
    6 rows selected.
    Edited by: user12231119 on Nov 16, 2009 9:19 PM

  • GROUP BY with multiple columns.

    I have little query about GROUP BY clause.
    Sometimes we will give multiple column names in GROUP BY .If it behaves in the same way as ORDER BY (multiple columns) i would love to have an example where I can use GROUP BY multiple columns. Anyways howsoever it behaves it will be really appreciated if anyone can explain a scenario where GROUP BY with multiple columns can be used.
    I know about the usage of aggregate functions with GROUP BY but using only one column.
    Thanks..!!!

    Hi,
    Group by is used for grouping of same records. check this bellow scenario
    SELECT registrationid, dateofbirth, age FROM prawin62 WHERE registrationid = 22;
    22     1/23/1975     54
    22     5/18/2011     66
    22     5/18/2011     66
    22     5/18/2011     66
    22     5/18/2011     66
    22     5/18/2011     66SELECT registrationid, sum(age) FROM prawin62 WHERE registrationid = 22 GROUP BY registrationid;
    22     384SELECT registrationid, dateofbirth, sum(age) FROM prawin62 WHERE registrationid = 22 GROUP BY registrationid, dateofbirth ;
    22     5/18/2011     330
    22     1/23/1975     54Thanks,
    Praveen

  • Repeat group header in multiple columns

    I have a group and the details section is set to format with multiple columns.  I have the repeat group header on each page option checked but I also want it to repeat group header if the group spans multiple columns.  Does anyone know how to do this?

    Thanks for your reply but I'm not sure how you copy a group header into another column if the data that is displayed there is dynamically displayed.  Please advise.  Thanks

  • Multiple Column Report Question

    Post Author: LCS213
    CA Forum: Crystal Reports
    I'm creating a student transcript report that has multiple columns, and is three groups deep.  The first two groups need to be in a columnar layout. However, I'd like the third group to contain a subreport that spans the width of the entire page. 
    Are there any options within Crystal XI to do this?  I know in the Section Expert, i can format the detail level with multiple columns, and on the Layout tab, I can select "Format Groups with multiple columns".  But that seems like it either formats ALL groups or NO groups.  Am I mistaken?  Is there a workaround I'm missing?
    Thanks in advance for any help on this issue!

    Hi Dan,
    According to your description, we are not clear about the “6 sections for each Additional task”. Do you mean six data records? If so, based on my understanding, there are three groups and eighteen records in your report. You want to make those records appear
    on eighteen separated pages, right?
    In Reporting Service, we can add a page break to groups within data regions to control the amount of information on each page. In your scenario, you should add page break to group “Sub task”, group “Additional Task” and details. As we tested in our environment,
    add page break to these records, the report appears in eighteen pages. Please refer to steps below:
    1.On Group Properties of Details1, choose “Between each instance of a group” option on Page Breaks page. Please refer to screenshot below:
     Choose same option on Group Properties for group “Month” and “Name”.
    2.Click drop-down button next to Column Groups, then choose Advanced Mode.
    3.Click on Static under Row Groups, set RepeatOnNewPage as True in Tablix Member Properties.
    4.Click Preview, the results before and after adding page break look like below:
    If you still have any question, please post some detail information or screenshot about the report design you expect.
    Best regards,
    Qiuyun Yu

  • Cross-Tab in multiple columns on same page rather than on multiple pages

    I have a report that shows temperature readings and the date/time of the reading in a cross tab as a part of a report.  The amount of readings causes the cross-tab to take up multiple pages.  What I would like to do is set the cross tab to appear three or four times on the same page before going to the next page to reduce the number of pages in my report.  Any ideas on how I can do this?
    This is what I have:
    Page 1:
    Date/Time1  |  Temp1
    Date/Time2  |  Temp2
    Date/Time3  |  Temp3
    Date/Time4  |  Temp4
    Page 2:
    Date/Time5  |  Temp5
    Date/Time6  |  Temp6
    Date/Time7  |  Temp7
    Date/Time8  |  Temp8
    What I want is:
    Page 1
    Date/Time1  |  Temp1..............Date/Time5  |  Temp5..............Date/Time9   |  Temp9
    Date/Time2  |  Temp2..............Date/Time6  |  Temp6..............Date/Time10  |  Temp10
    Date/Time3  |  Temp3..............Date/Time7  |  Temp7..............Date/Time11  |  Temp11
    Date/Time4  |  Temp4..............Date/Time8  |  Temp8..............Date/Time12  |  Temp12    
    Page 2
    Date/Time13  |  Temp17............Date/Time21  |  Temp21............Date/Time25  |  Temp25
    Date/Time14  |  Temp18............Date/Time22  |  Temp22............Date/Time26  |  Temp26
    Date/Time15  |  Temp19............Date/Time23  |  Temp23............Date/Time27  |  Temp27
    Date/Time16  |  Temp20............Date/Time24  |  Temp24............Date/Time28  |  Temp28        

    hello,
    Don's suggestion of creating a "mock cross tab" is a good one.
    you can also try this Multiple Columns formatting idea if you wish:
    1) create a new report
    2) create a group on your date field
    3) put a summary on your Temp field and move it into the group header of the group
    4) suppress the details section and the group footer
    5) right click on the details section header in the design mode and choose Section Expert
    6) in the Common tab, choose Format With Multiple Columns
    7) in the Layout tab, choose a Width of about 2.66"
    8) choose Down Then Across for Printing Directions
    9) choose Format Groups With Multiple Columns
    10) bring this new report into your existing report as a subreport
    jamie

  • Groups and Multi Column Reports

    I'm using CR for .Net 2003.  I've been running into a problem with the grouping feature, where groups are spanning multiple columns and are not being kept together, but only when spanning b/w columns.  However, the groups aren't being broken between pages.  Anyone else running into this?  Here's my setup:
    Page Header
    Group Header
    Details
    Group Footer
    Page Footer
    The "Group Header", "Details" and "Group Footer" are all set to Keep Together in the Selection Expert.  The layout of the "Details" section has "Format Groups with multiple Columns" checked.  (I only have two columns)  And my group options has the option "Keep Group Together" selected. 
    I was under the impression that if I have "Keep Group Together" it would keep the group together regardless of an end of page, or an end of column...but, maybe I have something misconfigured.
    advTHANKSance for any help!

    Confirm version of Crystal Reports and version of .NET.
    Also, have you applied any Service Packs to your version of CR?
    Ludek

  • Crystal Report multiple columns

    I'm having trouble with Crystal Report's multiple columns in the detail section.
    The details section, the multiple columns is checked then the printing direction is across - down. Since the form I am using is a pre-printed form, by estimation it can only allow at best 30 records in one page, that is 15 in the 1st half of the column and another 15 records on the next. For visual:
    Invoice No    Invoice Date        invoice total                                               Invoice No    Invoice Date        invoice total
    1                                                                                16
    2                                                                                17
    3                                                                                .
    .                                                                                28
    14                                                                                29
    15                                                                                30
    For some reason there is this giant space after the last set of rows before it prints out the page footer. This giant blank section disrupts the layout of the page footer section.
    Here are some info on the details section as configuration is involved:
    Format with  Multiple Columns - checked
    In Paging: New Page after 30 visible Records
    In Layout: Width: 3.5 in       Height: 0.0 in
                     Horizontal: 0.0 in      Vertical: 0.0 in     
    Printing Direction: Across-Down
    Anyone knows how to suppress it or have the page footer move upwards?
    P.S To see actual pre-printed form, please download this [http://www.mediafire.com/i/?csu0q75mjynys2k]
    Edited by: Khristine Angelei  Basilla on Mar 1, 2012 8:34 AM

    Now why didn't I try that out. Actually, initial plan was 2 subreports.
    So when I added the second subreport in the group footer section, it only prints the details on the last page, which should not be the case as I need to be printed on all pages.
    I'll test it out. I'll post an update soon.
    Thanks.

  • Format on multiple columns issue ...

    Post Author: needhelptoo
    CA Forum: Formula
    I'm having issues with the way the data is displaying.I am using the Format Multiple Columns.I have 3 across set.I have the Down and Across checked.My report with the 3 columns is a custom labels sheet.I need to have the down part always be 8 columns.i can't set that anywhere like the 3 columns across.as the sheet used to print the info are labels and perforated for each label (column)I have the following:1.
    Group Header #1 on InvoiceNumber. This have my invoice header
    information related to the customer of the invoice. Keep Together
    selected.2. Group Header #2 on a formula {@sort}. This is suppressed and as  a {@reset} formula in it.3. Details section has {@accum} and section suppressed. Keep Together selected.4. Group Footer #2 as the {@display} formula with Paragraph Formatting. Keep Together selected.5. Group Footer #1 on InvoiceNumber has add'l customer related info for the invoice.so 5 sections in my design view with 2 groups.It'll display the information in InvoiceNumber order in ascending order down first.But the last one on the 1st column is only part of the invoice info and the rest of it starts from the top of the 2nd column.and
    then shifts all the columns according to that. Which of course then
    does not print on the allotted space of the actual label. part of info
    is on one and the rest on another.obviously this won't work. I think i tried everything I can think of and I'm not expert. Barely a novice at this.any help would be appreciated!

    Post Author: V361
    CA Forum: Formula
    In the layout tab, have you tried the Gap between details ?, you should be able to produce a "mailing label type" report using detail size and gap between details... 

  • How to calculate the individual sums of multiple columns in a single query

    Hello,
    Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
    Will appreciate any help or suggestion.
    Thanks

    user13667036 wrote:
    Hello,
    Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
    Will appreciate any help or suggestion.
    ThanksLooks like you want a simple group by.
    select
              yr
         ,      mnth
         ,      region
         ,     sum(handled_package)
         ,     sum(expected_missing_package)
         ,     sum(actual_missing_package)
    from test
    group by
         yr, mnth, region
    order by      
         yr, mnth, region;I wouldn't recommend storing your data for year / month in 2 columns like that unless you have a really good reason. I would store it as a date column and add a check constraint to ensure that the date is always the first of the month, then format it out as you wish to the client.
    CREATE TABLE test
         year_month                              date,
        Region                     VARCHAR2(50),
        CITY                       VARCHAR2(50),             
        Handled_Package            NUMBER,       
        Expected_Missing_Package   NUMBER,   
        Actual_Missing_Package     NUMBER
    alter table test add constraint firs_of_month check (year_month = trunc(year_month, 'mm'));
    ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
      2  Values (to_date('2012-nov-12', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
    Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
    ERROR at line 1:
    ORA-02290: check constraint (TUBBY.FIRS_OF_MONTH) violated
    Elapsed: 00:00:00.03
    ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
      2  Values (to_date('2012-nov-01', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
    1 row created.
    Elapsed: 00:00:00.01
    ME_XE?select
      2        to_char(year_month, 'fmYYYY')    as year
      3     ,  to_char(year_month, 'fmMonth')   as month
      4     ,  Region
      5     ,  CITY
      6     ,  Handled_Package
      7     ,  Expected_Missing_Package
      8     ,  Actual_Missing_Package
      9  from test;
    YEAR         MONTH                REGION                         CITY                    HANDLED_PACKAGE EXPECTED_MISSING_PACKAGE ACTUAL_MISSING_PACKAGE
    2012         November             Western                        San Fransisco                       200                       10                      5
    1 row selected.
    Elapsed: 00:00:00.01
    ME_XE?Then you have nice a nice and easy validation that ensures you data integrity.
    Cheers,

  • How to get a distinct count of multiple columns

    I've done this before and I'll be darned why I can't recall this.
    Table with 3 columns with the primary key defined in column a.
    Row a b c
    num.
    1 020 how abc
    2 030 why def
    3 010 not ghi
    4 040 how abc
    5 050 yes def
    6 060 why def
    So what I want is a count of the unique values for columns b and c as if b and c were actually one field.
    So the result of the query would be:
    Count = 4 unique rows.
    Hopefully I'm making some sort of sense. It's a bit much to ask about the number of occurrences of each duplicate value, I'm sure just getting count of the unique rows of the non-indexed rows will be sufficient. Since the query is meant to be universal for multiple columns of numeric and alphanumeric data and can be expanded for multiple columns, I am simply trying to get a basic skeleton that works for an "on the fly" analysis.

    Thanks to all of you. I had the idea and just couldn't nail it down. You did it.
    All of you understood what I poorly communicated. My apologies for the lack of prep with a table, I was running patches on the system and couldn't dare interrupt it on my laptop and starting Oracle 11 while Micro$lop was patching all sorts of evil code. This is something I'm setting up on my own time so it's a work I'm going to try to be proud of. So there will be plenty of instrumentation and debugging code for timing.
    I'd thought of concatenating columns and was worried it wouldn't backport to older Oracle versions (work goes back to 8.1.7) with nulls and other goofy things like long raw fields or lob/clobs plus the other DBs that are at various sites. What I'm trying to do is improve on a crappy data analysis tool SAP provides to use with reporting unique columns. (Basis people could recognize this as DB05). I tried dragging out the SQL that their ABAP/4 language generates from an SQL trace but it was unusable and often dies on internal storage which on most sites is about 4GB per process. Needless to say, the program is wasteful and I'm trying to keep the work on the DB where it belongs and discourage cowboys from doing this in the DB on the fly and at the same time make it simpler for junior members to use while having a semblance of an audit trail.
    What I'm trying to do is work out a tool that checks all the crappy secondary indexes that were created by folks who seem to think in ways that are from an alien species not yet speculated about even with the strongest psychedelics. One of them actually decreases performance by a minimum factor of 5. It's not much when it's 5 seconds but when the response time averages about 3 hours beforehand, you can imagine what it was like afterward. In this particular case, the "logic" was that the index needed to be defined by the order of the fields of the select clause. Some myths never die. So it's not easy to work out which ones haven't been used in a long time, so it's down to finding which of the custom ones are actually bad in terms of selectivity. Some of these may have made a little bit of sense when the system was started up, now that some of these have millions of rows instead of a few thousand, thaw tend to expose the flaws in design.
    I'm also trying to make this work on multiple DBs such as DB2, MaxDB and (sob) SQL Squealer. The idea is to write this in ABAP code as a utility without the overhead of internal tables in ABAP as some of these tables are many millions of rows and I have to account for the size in memory. (ABAP field sizes in internal memory are generally much larger than the actual DB lengths. so every bit helps!) So I'm trying to create actual SQL on the fly and use it internally without going through the SAP DB interface which limits the type of SQL functions used and all the overhead. It's intended to grab a secondary index and if there are more than 2 fields defined, work it backwards to show unique values for all columns, all columns - 1, all columns - 2 and so on back to the initial column in the index.
    Why does this seem important? On Oracle I can generate histograms but those can often screw up SAP. On other DBs, the indexing cardinality is much more important, particularly with DB optimizers that make some odd decisions. So I need evidence I can push to folks who will only understand if there's a plain and simple analysis that explains it (almost) in crayon.
    I'm testing null values next (which worked!) but these suggestions all seem to follow the same idea which won't work in ABAP without some serious memory issues. So I'm down to this type of coding:
    exec sql.
    <dynamically generated true SQL>
    end-exec.
    rather than using ABAP with their concept of "open SQL" and the DB interface with all the overhead.
    RB's suggestion of the UNION ALL wasn't quite what I was looking for BUT it made me think that this would be a nice enhancement for evaluations!
    So the candidates that seem to work for what I wanted are as follows:
    SQL> SELECT COUNT (MIN (0)) AS distinct_col3_col4_cnt
    2 from rb group by b, c;
    DISTINCT_COL3_COL4_CNT
    7
    select count(distinct(b || c)) num_rows from rb;
    So thanks also to Frank, APNL and Nimesh for their examples. Now the fun starts as I spec out the processing.

  • Top N Analysis with multiple columns

    Hi
    I am using Oracle 9i. I do have a table which contains datewise promotional material types for an organisation.
    The structure is as follows:
    CREATE TABLE TEST
    (CDATE DATE,
    BROCHURE VARCHAR2(1),
    WEBSITE VARCHAR2(1),
    DIRECT_MAIL VARCHAR2(1),
    PRESS_RELEASE VARCHAR2(1),
    JOURNAL_AD VARCHAR2(1)
    and the sample data is as follows:
    CDate          Brochure     Website     Direct_Mail     Press_Release Journal_Ad
    01/04/1996     Y Y Y N N
    02/04/1996     Y Y N N N
    23/06/1996     Y N Y Y N
    13/09/1996     Y Y N N N
    01/04/1997     Y Y N N N
    02/04/1997     Y Y Y N Y
    23/06/1997     N Y N N Y
    13/09/1997     Y Y N N N
    01/04/1998     Y Y Y N N
    02/04/1998     Y N N Y N
    23/06/1998     N Y N N Y
    13/09/1998     Y Y N N Y
    01/04/1999     Y Y Y N Y
    02/04/1999     Y N N Y N
    23/06/1999     N Y N N N
    13/09/1999     Y Y Y N N
    I want to have year wise top 4 promotional types in terms of count of 'Y' only. The result should be like as follows:
    YEAR:1996
    TYPE     COUNT
    BROCHURE 4
    WEBSITE 3
    DIRECT_MAIL 2
    PRESS_RELEASE 1
    JOURNAL_AD 0
    YEAR:1997
    TYPE     COUNT
    WEBSITE 4
    BROCHURE 3
    JOURNAL_AD 2
    DIRECT_MAIL 1
    PRESS_RELEASE 1
    Please suggest a solution for the same. I am not able to sort it for multiple columns.
    Regards
    MS

    One of the questions that must be asked when you have a requirement to only show the top N ranked items in a list, is "what about a tie in the ranking?".
    Oracle has two ranking functions that allow you to deal with either requirement - RANK and DENSE_RANK. Both operate as either analytic or aggregate functions, so either will work for your requirements. The previous posting by Miguel demonstrated how to decode your Y/N flags and pivot the data.
    In this example, I've taken the liberty of adding some data to year 2000 that will show the difference between RANK and DENSE_RANK as well as how to use them to filter your results.
    First, here's the decoded/pivoted data:
    SQL>WITH test AS
      2  (         SELECT TO_DATE('01/04/1996','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      3  UNION ALL SELECT TO_DATE('02/04/1996','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      4  UNION ALL SELECT TO_DATE('23/06/1996','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'N' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      5  UNION ALL SELECT TO_DATE('13/09/1996','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      6  UNION ALL SELECT TO_DATE('01/04/1997','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      7  UNION ALL SELECT TO_DATE('02/04/1997','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
      8  UNION ALL SELECT TO_DATE('23/06/1997','dd/mm/yyyy') AS CDATE, 'N' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
      9  UNION ALL SELECT TO_DATE('13/09/1997','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    10  UNION ALL SELECT TO_DATE('01/04/1998','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    11  UNION ALL SELECT TO_DATE('02/04/1998','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'N' AS WEBSITE, 'N' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    12  UNION ALL SELECT TO_DATE('23/06/1998','dd/mm/yyyy') AS CDATE, 'N' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
    13  UNION ALL SELECT TO_DATE('13/09/1998','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
    14  UNION ALL SELECT TO_DATE('01/04/1999','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
    15  UNION ALL SELECT TO_DATE('02/04/1999','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'N' AS WEBSITE, 'N' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    16  UNION ALL SELECT TO_DATE('23/06/1999','dd/mm/yyyy') AS CDATE, 'N' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    17  UNION ALL SELECT TO_DATE('13/09/1999','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    18  UNION ALL SELECT TO_DATE('01/04/2000','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
    19  UNION ALL SELECT TO_DATE('02/04/2000','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    20  UNION ALL SELECT TO_DATE('23/06/2000','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    21  UNION ALL SELECT TO_DATE('13/09/2000','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    22  )
    23  SELECT cyear
    24        ,ctype
    25        ,RANK()       OVER (PARTITION BY cyear ORDER BY num_media DESC) ranking
    26        ,DENSE_RANK() OVER (PARTITION BY cyear ORDER BY num_media DESC) dense_ranking
    27  FROM (SELECT TRUNC(CDATE,'Y') CYEAR
    28             ,'BROCHURE' CTYPE, SUM(DECODE(BROCHURE, 'Y', 1, 0)) NUM_MEDIA
    29        FROM test
    30        GROUP BY TRUNC(CDATE,'Y')
    31        UNION ALL
    32        SELECT TRUNC(CDATE,'Y') CYEAR
    33             ,'WEBSITE' CTYPE, SUM(DECODE(WEBSITE, 'Y', 1, 0))
    34        FROM test
    35        GROUP BY TRUNC(CDATE,'Y')
    36        UNION ALL
    37        SELECT TRUNC(CDATE,'Y') CYEAR
    38             ,'DIRECT_MAIL' CTYPE, SUM(DECODE(DIRECT_MAIL, 'Y', 1, 0))
    39        FROM test
    40        GROUP BY TRUNC(CDATE,'Y')
    41        UNION ALL
    42        SELECT TRUNC(CDATE,'Y') CYEAR
    43             ,'PRESS_RELEASE' CTYPE, SUM(DECODE(PRESS_RELEASE, 'Y', 1, 0))
    44        FROM test
    45        GROUP BY TRUNC(CDATE,'Y')
    46        UNION ALL
    47        SELECT TRUNC(CDATE,'Y') CYEAR
    48             ,'JOURNAL_AD' CTYPE, SUM(DECODE(JOURNAL_AD, 'Y', 1, 0))
    49        FROM test
    50        GROUP BY TRUNC(CDATE,'Y')
    51       )
    52* order by cyear desc, ranking
    53  /
    CYEAR                         CTYPE             RANKING DENSE_RANKING
    01-Jan-2000 00:00:00          BROCHURE                1             1
    01-Jan-2000 00:00:00          WEBSITE                 1             1
    01-Jan-2000 00:00:00          DIRECT_MAIL             3             2
    01-Jan-2000 00:00:00          PRESS_RELEASE           4             3
    01-Jan-2000 00:00:00          JOURNAL_AD              5             4
    01-Jan-1999 00:00:00          BROCHURE                1             1
    01-Jan-1999 00:00:00          WEBSITE                 1             1
    01-Jan-1999 00:00:00          DIRECT_MAIL             3             2
    01-Jan-1999 00:00:00          PRESS_RELEASE           4             3
    01-Jan-1999 00:00:00          JOURNAL_AD              4             3
    01-Jan-1998 00:00:00          BROCHURE                1             1
    01-Jan-1998 00:00:00          WEBSITE                 1             1
    01-Jan-1998 00:00:00          JOURNAL_AD              3             2
    01-Jan-1998 00:00:00          DIRECT_MAIL             4             3
    01-Jan-1998 00:00:00          PRESS_RELEASE           4             3
    01-Jan-1997 00:00:00          WEBSITE                 1             1
    01-Jan-1997 00:00:00          BROCHURE                2             2
    01-Jan-1997 00:00:00          JOURNAL_AD              3             3
    01-Jan-1997 00:00:00          DIRECT_MAIL             4             4
    01-Jan-1997 00:00:00          PRESS_RELEASE           5             5
    01-Jan-1996 00:00:00          BROCHURE                1             1
    01-Jan-1996 00:00:00          WEBSITE                 2             2
    01-Jan-1996 00:00:00          DIRECT_MAIL             3             3
    01-Jan-1996 00:00:00          PRESS_RELEASE           4             4
    01-Jan-1996 00:00:00          JOURNAL_AD              5             5You can see that in year 2000 there is a tie for first place (ranking #1). The RANK function will name the second highest count 3 (skipping the rank of 2 due to the tie), while the DENSE_RANK function will not skip a ranking.
    Now, to filter on the ranking, wrap your query in another in-line view like this - but use which ever ranking function YOUR requirements call for:
    SQL>WITH test AS
      2  (         SELECT TO_DATE('01/04/1996','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      3  UNION ALL SELECT TO_DATE('02/04/1996','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      4  UNION ALL SELECT TO_DATE('23/06/1996','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'N' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      5  UNION ALL SELECT TO_DATE('13/09/1996','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      6  UNION ALL SELECT TO_DATE('01/04/1997','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
      7  UNION ALL SELECT TO_DATE('02/04/1997','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
      8  UNION ALL SELECT TO_DATE('23/06/1997','dd/mm/yyyy') AS CDATE, 'N' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
      9  UNION ALL SELECT TO_DATE('13/09/1997','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    10  UNION ALL SELECT TO_DATE('01/04/1998','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    11  UNION ALL SELECT TO_DATE('02/04/1998','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'N' AS WEBSITE, 'N' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    12  UNION ALL SELECT TO_DATE('23/06/1998','dd/mm/yyyy') AS CDATE, 'N' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
    13  UNION ALL SELECT TO_DATE('13/09/1998','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
    14  UNION ALL SELECT TO_DATE('01/04/1999','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
    15  UNION ALL SELECT TO_DATE('02/04/1999','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'N' AS WEBSITE, 'N' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    16  UNION ALL SELECT TO_DATE('23/06/1999','dd/mm/yyyy') AS CDATE, 'N' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    17  UNION ALL SELECT TO_DATE('13/09/1999','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    18  UNION ALL SELECT TO_DATE('01/04/2000','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'Y' AS JOURNAL_AD FROM DUAL
    19  UNION ALL SELECT TO_DATE('02/04/2000','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    20  UNION ALL SELECT TO_DATE('23/06/2000','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'N' AS DIRECT_MAIL, 'N' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    21  UNION ALL SELECT TO_DATE('13/09/2000','dd/mm/yyyy') AS CDATE, 'Y' AS BROCHURE, 'Y' AS WEBSITE, 'Y' AS DIRECT_MAIL, 'Y' AS PRESS_RELEASE, 'N' AS JOURNAL_AD FROM DUAL
    22  )
    23  SELECT * FROM (
    24      SELECT cyear
    25            ,ctype
    26            ,RANK()       OVER (PARTITION BY cyear ORDER BY num_media DESC) ranking
    27            ,DENSE_RANK() OVER (PARTITION BY cyear ORDER BY num_media DESC) dense_ranking
    28      FROM (SELECT TRUNC(CDATE,'Y') CYEAR
    29                 ,'BROCHURE' CTYPE, SUM(DECODE(BROCHURE, 'Y', 1, 0)) NUM_MEDIA
    30            FROM test
    31            GROUP BY TRUNC(CDATE,'Y')
    32            UNION ALL
    33            SELECT TRUNC(CDATE,'Y') CYEAR
    34                 ,'WEBSITE' CTYPE, SUM(DECODE(WEBSITE, 'Y', 1, 0))
    35            FROM test
    36            GROUP BY TRUNC(CDATE,'Y')
    37            UNION ALL
    38            SELECT TRUNC(CDATE,'Y') CYEAR
    39                 ,'DIRECT_MAIL' CTYPE, SUM(DECODE(DIRECT_MAIL, 'Y', 1, 0))
    40            FROM test
    41            GROUP BY TRUNC(CDATE,'Y')
    42            UNION ALL
    43            SELECT TRUNC(CDATE,'Y') CYEAR
    44                 ,'PRESS_RELEASE' CTYPE, SUM(DECODE(PRESS_RELEASE, 'Y', 1, 0))
    45            FROM test
    46            GROUP BY TRUNC(CDATE,'Y')
    47            UNION ALL
    48            SELECT TRUNC(CDATE,'Y') CYEAR
    49                 ,'JOURNAL_AD' CTYPE, SUM(DECODE(JOURNAL_AD, 'Y', 1, 0))
    50            FROM test
    51            GROUP BY TRUNC(CDATE,'Y')
    52           )
    53      )
    54  where RANKING <= 4
    55* order by cyear desc, ranking
    56  /
    CYEAR                         CTYPE             RANKING DENSE_RANKING
    01-Jan-2000 00:00:00          WEBSITE                 1             1
    01-Jan-2000 00:00:00          BROCHURE                1             1
    01-Jan-2000 00:00:00          DIRECT_MAIL             3             2
    01-Jan-2000 00:00:00          PRESS_RELEASE           4             3
    01-Jan-1999 00:00:00          BROCHURE                1             1
    01-Jan-1999 00:00:00          WEBSITE                 1             1
    01-Jan-1999 00:00:00          DIRECT_MAIL             3             2
    01-Jan-1999 00:00:00          JOURNAL_AD              4             3
    01-Jan-1999 00:00:00          PRESS_RELEASE           4             3
    01-Jan-1998 00:00:00          BROCHURE                1             1
    01-Jan-1998 00:00:00          WEBSITE                 1             1
    01-Jan-1998 00:00:00          JOURNAL_AD              3             2
    01-Jan-1998 00:00:00          PRESS_RELEASE           4             3
    01-Jan-1998 00:00:00          DIRECT_MAIL             4             3
    01-Jan-1997 00:00:00          WEBSITE                 1             1
    01-Jan-1997 00:00:00          BROCHURE                2             2
    01-Jan-1997 00:00:00          JOURNAL_AD              3             3
    01-Jan-1997 00:00:00          DIRECT_MAIL             4             4
    01-Jan-1996 00:00:00          BROCHURE                1             1
    01-Jan-1996 00:00:00          WEBSITE                 2             2
    01-Jan-1996 00:00:00          DIRECT_MAIL             3             3
    01-Jan-1996 00:00:00          PRESS_RELEASE           4             4

  • Is it possible to make a condition for formatting multiple column?

    I am working on financial report like Balance Sheet. So that I am going to have 2 column and 1 on left, 2 and 3 on right.
    I tried to use format multiple columns but can't find any method to define where to break.

    when you create a stored procedure or use a command file( i believe) you can create CASE statements
    CASE WHEN ='BLUE' THEN 'COLUMN1'
    WHEN ='GREEN' THEN 'COLUMN2' END AS BUCKET1
    when you use this as the dataset you will see this as a field
    you can then group by the fields created.

Maybe you are looking for

  • Wrong apple ID for family sharing purchases

    I use one email address for iCloud and one for iTunes purchases. I have signed up to family sharing using my iTunes account, but when a family member requests approval for an app purchase, it defaults to my iCloud email address (the address is greyed

  • SWI5 transaction - is there a table view ?

    Hi I am trying to pull a report of outstanding approval inbox items (TS1230097 - for leave requests) that I see when I go to tcode SWI5 for managers. If I run a report it does not give me the manager id in it which I need. Is there a table view for S

  • IMAGES ON OLD PAGES FILE NOT APPEARING CORRECTLY ON NEW MAC

    Hi, I hope you can help me. My 2nd Mac crashed a few months ago was 10.5.8 (I believe) and now I have a new one with 10.6.4 loaded. My problem is I have a reasonably sized file (a book) full of text and images, when the book was typed the images were

  • Unique Identifier Variables

    I am calling a coldfusion remote object, and I wish to take a variable that is stored as a unique identifier and pass it in my flex app. Here is the error I presently get, attempting to store it as a string. [Macromedia][SQLServer JDBC Driver][SQLSer

  • Embed captions in EXIF data

    Hello, I have written captions to my pictures (a few thousand of them) that I want to share with my "Windows" friends. Apparently the captions are not embedded when I export the files ("File" menu). How can I share my photos WITH captions? /Lennart