aggregate queries - view the right output

How I can do this query to display the results as follows:

BIOL2554An a: (BIOL 1102, 1109, 2100-3999, 102, 109, or 210-399) (CHEM 1100-3999 or 100-399) (EOS 1100-3999 or 100-399) (MATH 1100-3999 or 100-399) (PHYS 1100-3999 or 100-399)

It displays this:

BIOL2554BIOL 1102-BIOL 1109-BIOL 2100-3999 CHEM 1100-3999 EOS 1100-3999 MATH 1100-3999 PHYS 100-399 BIOL 102-210-399 109 BIOL - BIOL CHEM 100-399 EOS 100-399 MATH 100-399 PHYS 1100-3999

This is the query

envelope format A60 outstr col

with x as)

SELECT

AREA                 ,

TERM_CODE_EFF,

SSET                  ,

SUBSET,

SUBJ_CODE,

CRSE_NUMB_LOW,

CRSE_NUMB_HIGH,

ATTS_CODE,

TVATTS_DESC,

-case when a.subj_code is null then substr (b.tvatts_desc, 1, instr(b.tvatts_desc,':')-1) to another a.subj_code end drvsubj_code

Of

SMRACAA_TEST has,

TVATTS b

WHERE

-ZONE = "ECON2555."

ATTS_CODE = TVATTS_CODE (+)

order by Tess, subset)

, like)

Select x.*

,

case

When the tvatts_desc is not null then ' (Placement in ': substr (tvatts_desc, instr(tvatts_desc,':') + 1) | ")' »  || ' '

When the crse_numb_high is not null then subj_code | ' '|| crse_numb_low | '-' || crse_numb_high | ' '

When crse_numb_high is null and row_number() over (partition of domain, Tess order by subset) = 1

then ' ' | subj_code | ' '|| crse_numb_low | "or" | Lead (crse_numb_low) over (partition of domain, Tess order by subset)

Another null

end tvstr

x where drvsubj_code is not null

)

Select the separate area, listagg (tvstr) Group (order by null) on outstr (partition by area)

of y;

Here are some scripts:

CREATE TABLE SMRACAA_TEST

(

AREA VARCHAR2 (10 CHAR) NOT NULL,

TERM_CODE_EFF VARCHAR2 (6 CHAR) NOT NULL,

TESS VARCHAR2 (3 CHAR),

NUMBER (3) SUBSET,.

SUBJ_CODE VARCHAR2 (4 CHAR),

CRSE_NUMB_LOW VARCHAR2 (5 CHAR),

CRSE_NUMB_HIGH VARCHAR2 (5 CHAR),

ATTS_CODE VARCHAR2 (4 CHAR)

)

---

CREATE TABLE TVATTS

(

TVATTS_CODE VARCHAR2 (4 CHAR) NOT NULL,

TVATTS_DESC VARCHAR2 (30 CHAR) NOT NULL

)

"' INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) select 'BIOL2554', '201420', '10', '110', 'BIO', '1102', ' ',' ' FROM DUAL;

"' INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) select 'BIOL2554', '201420', '10', '120', 'BIO', '1109', ' ',' ' FROM DUAL;

"" "INSERT IN SMRACAA_TEST (AREA, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', 'A10', select '130', 'BIO',' 2 100 pi, 3999 ' ', ' ' FROM DUAL;

INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', 'A10', select '140', 'CHEM', '1100', ' 3999',' ' FROM DUAL;

INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', 'A10', select '150', 'EOS', '1100', ' 3999',' ' FROM DUAL;

INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', 'A10', select '160', 'MATH', '1100', ' 3999',' ' FROM DUAL;

INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', 'A10', select '170', 'PHYSICAL', '1100', ' 3999',' ' FROM DUAL;

"' INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) select 'BIOL2554', '201420', '10', '180', 'BIO', '102', ' ',' ' FROM DUAL;

"' INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) select 'BIOL2554', '201420', '10', '190', 'BIO', '109', ' ',' ' FROM DUAL;

INSERT IN SMRACAA_TEST (AREA, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', 'A10', select '200', 'BIO', ' 210 feet, ' 399',' ' FROM DUAL;

INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', 'A10', select ' 210 feet, 'CHEM', '100', '399',' ' FROM DUAL;

INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', '10', select '220', 'EOS', ' 100', '399',' ' FROM DUAL;

INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', '10', select '230', 'MATH', ' 100', '399',' ' FROM DUAL;

INSERT INTO SMRACAA_TEST (BOX, TERM_CODE_EFF, TESS, subset, SUBJ_CODE, CRSE_NUMB_LOW, CRSE_NUMB_HIGH, ATTS_CODE) 'BIOL2554', '201420', '10', select '240', 'PHYSICAL', ' 100', '399',' ' FROM DUAL;

--

INSERT INTO TVATTS (TVATTS_CODE, TVATTS_DESC), SELECT 'R672', ' MATH: MATH 1700' FROM DUAL;

INSERT INTO TVATTS (TVATTS_CODE, TVATTS_DESC), SELECT 'R675', ' MATH: MATH 1750' FROM DUAL;

INSERT INTO TVATTS (TVATTS_CODE, TVATTS_DESC), SELECT 'R678', ' MATH: MATH 1800' FROM DUAL;

INSERT INTO TVATTS (TVATTS_CODE, TVATTS_DESC), SELECT 'R683', ' MATH: MATH 2000' FROM DUAL;

Try the following query.

with x as)

SELECT

AREA                 ,

TERM_CODE_EFF,

SSET                  ,

SUBSET,

SUBJ_CODE,

CRSE_NUMB_LOW,

CRSE_NUMB_HIGH,

ATTS_CODE,

TVATTS_DESC,

-case when a.subj_code is null then substr (b.tvatts_desc, 1, instr(b.tvatts_desc,':')-1) to another a.subj_code end drvsubj_code

Of

SMRACAA_TEST has,

TVATTS b

WHERE

-ZONE = "ECON2555."

ATTS_CODE = TVATTS_CODE (+)

order by Tess, subset)

, like)

Select x.*

,

case

When the tvatts_desc is not null then ' (Placement in ': substr (tvatts_desc, instr(tvatts_desc,':') + 1) | ")' »  || ' '

ROW_NUMBER () OVER (PARTITION BY AREA, TESS, SUBJ_CODE ORDER BY TESS) = 1 THEN SUBJ_CODE | » '||

(CASE WHEN CRSE_NUMB_LOW IS NOT NULL AND TRIM (CRSE_NUMB_HIGH) IS NULL THEN CRSE_NUMB_LOW |) «, »

WHEN CRSE_NUMB_LOW IS NOT NULL AND THAT TRIM (CRSE_NUMB_HIGH) IS NOT NULL, THEN CRSE_NUMB_LOW | » -'|| TRIM (CRSE_NUMB_HIGH) | ',' END)

WHEN TRIM (CRSE_NUMB_HIGH) IS NOT NULL AND CRSE_NUMB_LOW IS NOT NULL

AND LEAD (SUBSET) OVER (PARTITION BY DECREE OF THE SUBJ_CODE SECTOR, TESS, A SUBSET) IS NOT NULL THEN ' ' | CRSE_NUMB_LOW | » -'|| TRIM (CRSE_NUMB_HIGH) | «, »

WHEN TRIM (CRSE_NUMB_HIGH) IS NULL AND ADVANCE (SUBSET, 2) OVER (PARTITION BY DECREE OF THE SUBJ_CODE SECTOR, TESS, A SUBSET) IS NULL THEN ' ' | CRSE_NUMB_LOW

WHEN TRIM (CRSE_NUMB_HIGH) IS NULL AND ADVANCE (SUBSET, 2) OVER (PARTITION BY DECREE OF THE SUBJ_CODE SECTOR, TESS, A SUBSET) IS NOT NULL THEN ' ' | CRSE_NUMB_LOW | «, »

WHEN LEAD THEN (subset) OVER(PARTITION BY AREA,SSET,SUBJ_CODE ORDER BY SUBSET) IS NULL 'or'. CRSE_NUMB_LOW | » -'|| TRIM (CRSE_NUMB_HIGH)

Another null

end tvstr

ROW_NUMBER () on the rn (partition by area, Tess, subj_code order of subset)

x where drvsubj_code is not null

)

District CHIC | "One of: ' | LISTAGG (OUTSTR, "GOLD") WITHIN THE GROUP (CONTROL AREA)

DE)

SELECT a distinct area,

REPLACE ('(': listagg (tvstr) within the Group (domain partition, SUBJ_CODE) (order by null) |')) (',', or ',' or ') outstr

OF Y

ORDER BY AREA)

GROUP BY AREA;

OUTPUT:

BIOL2554 One of: (BIOL 1102, 1109, 2100-3999, 102, 109, or 210-399) (CHEM 1100-3999 or 100-399) (EOS 1100-3999 or 100-399) (MATH 1100-3999 or 100-399) (PHYS 1100-3999 or 100-399)

Post edited by: Parth272025

Tags: Database

Similar Questions

  • by using the analytical function to get the right output.

    Hello all;

    I have the following date of sample below
    create table temp_one
    (
           id number(30),   
          placeid varchar2(400),
          issuedate  date,
          person varchar2(400),
          failures number(30),
          primary key(id)
    );
    
    insert into temp_one values (1, 'NY', to_date('03/04/2011', 'MM/DD/YYYY'), 'John', 3);
    
    insert into temp_one values (2, 'NY', to_date('03/03/2011', 'MM/DD/YYYY'), 'Adam', 7);
    
    insert into temp_one values (3, 'Mexico', to_date('03/04/2011', 'MM/DD/YYYY'), 'Wendy', 3);
    
    insert into temp_one values (4, 'Mexico', to_date('03/14/2011', 'MM/DD/YYYY'), 'Gerry', 3);
    
    insert into temp_one values (5, 'Mexico', to_date('03/15/2011', 'MM/DD/YYYY'), 'Zick', 9);
    
    insert into temp_one values (6, 'London', to_date('03/16/2011', 'MM/DD/YYYY'), 'Mike', 8);
    It's the output I want
    placeid       issueperiod                               failures
    NY              02/28/2011 - 03/06/2011          10
    Mexico       02/28/2011 - 03/06/2011           3
    Mexico        03/14/2011 - 03/20/2011          12
    London        03/14/2011 - 03/20/2011          8
    Any help is appreciated. I'll post my request as soon as I can think of a good logic for this...

    Hello

    user13328581 wrote:
    ... Please note, I'm still learning how to use analytical functions.

    It doesn't matter; analytical functions will not help in this problem. The SUM aggregate function is all you need.
    But what do you need to GROUP BY? What is the value of each row of the result will represent? A placeid? Yes, each line will represent only placedid, but it will be divided further. You want a separate line of the output for each placeid and every week, then you'll want of the week and GROUP BY placeid. You don't want to GROUP BY the raw issuedate; that would put on 3 March and 4 March in separate groups. And you don't want to GROUP BY failures; This would mean that a line with 3 failures could never be in the same group in line with 9 failures.

    This becomes the output you posted from the sample data you posted:

    SELECT       placeid
    ,             TO_CHAR ( TRUNC (issuedate, 'IW')
                  , 'MM/DD/YYYY'
                ) || ' - '|| TO_CHAR ( TRUNC (issuedate, 'IW') + 6
                                             , 'MM/DD/YYY'
                               )     AS issueperiod
    ,       SUM (failures)                  AS sumfailures
    FROM        temp_one
    GROUP BY  placeid
    ,            TRUNC (issuedate, 'IW')
    ;
    

    You can use a subquery to calculate TRUNC (issuedate, 'IW') once. The code would be of about as complicated, efficiency probably will not improve substantially and the results would be the same.

  • Need a program to view the voice output and microphone camera in c#

    I'm looking for a program display the exit camera and mic voice using c# in windows 7

    Hello

    The question you posted would be better suited in the MSDN Forums. I would recommend posting your query in the MSDN Forums
  • Why was the swype gesture to the right to view open deleted tabs?

    In previous versions of Firefox for Android, you could swype the screen with 2 fingers to the right, and he would show a list of open tabs. This design was smooth and very easy access.
    Why this was removed?
    Is all swyping equivalent to the new version of the tabs on the top?
    Thank you

    There were many complainants that Firefox has no legs. UX testing, with the entire population, the UI Slides tabs was generally regarded as impossible.

    In addition he caused problems with pages that use the touch events. For example, panoramic view of Google Maps.

  • I was on facebook and remove an icon by using the right-click menu, but then all my photos and pictures of profile, could no longer be seen. I was able to view them in the browser, so it's something I've done in Firefox. How can I unlock a site? "

    I was on facebook and remove an icon by using the right-click menu, but then all my photos and pictures of profile, could no longer be seen. I was able to view them in the browser, so it's something I've done in Firefox. How can I unlock a site?

    If you select that right click menu context then you block all images from this area and not a specific image, so do not use that.

    • Check exceptions in tools > Options > content: Load Images > Exceptions (for example sphotos.ak.fbcdn.net)

    You can use the following steps to check if the images are blocked:

    • Click on the "More information" button to open the "Page Info" with the Security tab selected (also accessible via "tools > Page Info").
    • Go to the Media of the window tab "tools > Page Info.
    • Select the first link of the image and scroll down through the list with the arrow down.
    • If an image in the list is grayed out and there is a check mark in the box "block Images of..." and remove this mark to unlock the images from this area.
  • mail splitter bar on the right is blocked can not view individual emails without double click

    mail splitter bar on the right is blocked can not view individual emails without double click

    Hi Mike,.

    It seems that the e-mail message preview area is hidden in the mail on your Mac mini. The article below was created for Mac OS X Mavericks, but you can use the instructions that it provides to change the size of the message preview area in Mail for OS X El Capitan similarly.

    Mail (Mavericks): Change the messages displayed

    Change the preview of the message

    Resize the preview area:

    Drag the bar that separates the message list and the preview left or right area.

    Show or hide the preview area:

    Double-click on the separator bar.

    See you soon.

  • The view from my office is rotated 90 degrees to the right. How can I get it back to normal?

    The view from my office is rotated 90 degrees to the right.  How can I get it back to normal?

    The view from my office is rotated 90 degrees to the right.  How can I get it back to normal?

    ATL + Ctrl and hold, press the up/down, left / right arrow keys to adjusment. I think that your case will be the UP key.
    Or, you can right-click on the free space of the desktop > click on the Graphics Options > click > 90 degrees Rotation

    t-4-2

  • Limit the rights Adminitrator view

    Hello, we limit the rights in administrator mode.  We run the version 6.0 of the Horizon with VMware 5.5 hosts.

    The reason is that we have two departments that must manage different hens. If we want to have A Department only be able to manage lets say 1 and 2 chicken and B Department only eats chicken 3 and 4.

    Basically I don't want someone in the Department has power accidentally make changes to pool 3 and 4.  Technically, I don't mind if they can view, but I don't want to make any changes to the other pools except those there Department.

    Is this possible?

    I have only 5 hosts, so I can't configure separate hosts for each departments.  I can set up separate connection servers if that helps somehow.


    Any ideas would be appreciated

    Mike

    You can configure roles and access groups through the Configuration of the display, Administration tab.   That should allow you restrict permissions to specific pools.

  • I want to set up an online quotation tool in my view based on a small number of variable input by the visitor. If someone has done this through Muse and able to assist / point me in the right direction please? Thank you!

    I want to set up an online quotation tool in my view based on a small number of variable input by the visitor. If someone has done this through Muse and able to assist / point me in the right direction please? Thank you!

    Hello

    These discussions could be useful

    I need to put a form to give a quote, does anyone have any ideas

    "Click to add to your" function

    Get the Quote button functionality

    Let me know if you have any question.

  • Unable to synchronize files; Click here to view the online help. This message keeps appearing at the top right of my iMac and no matter what I do it keep appearing.

    Unable to synchronize files; Click here to view the online help. This message keeps appearing at the top right of my iMac and no matter what I do it keep appearing.

    Hello

    Please see the link below.

    Error: "unable to sync files.

    Hope this will help you.

    Kind regards

    Hervé Khare

  • Align the af:output on the right side at the top of the facet

    Hi guys,.

    I'm trying to align af:output on the right side at the top of the side but is not working.how can I do.


    < f: facet = 'top' name >
    < af:panelGroupLayout layout = "horizontal".
    xmlns:af = "http://xmlns.oracle.com/adf/faces/rich".
    ID = "pgl1" styleClass = "AFStretchWidth" >
    < af:panelHeader text = "JCB Workbench" id = "ph1" / >
    < af:outputText value = "#{bindings." Name.inputValue}"id ="ot1"/ >
    < / af:panelGroupLayout >
    < / f: facet >

    Thank you
    Raul

    Hello

    set

    
    
    
    
    
    
    
  • Problem with 'small black line at the right margin' with Folio Builder / Viewer to Adobe in the Ipad. ID CC.

    Hello

    When I create a Folio Builder and I check my project Id in the Adobe viewer (sometimes in the Ipad app and Desktop Viewer), I can see a black line at the right margin (maybe 4 px). And I can not set my background (it is an object with a color) to use the "full resolution available to the app in the ipad" and Yes, I'm using rules and I see that my object wallpaper is 1024 x 768. I tried several projects and upgraded the project for the "30" version

    But I am a new user with the ID/DPS. So, is this a bug reported? Or I'm doing sth wrong?

    And for me, the most important issue, will fix this when I send my project to the applestore and DPS transform my Folio to the store? Or what I see now that's what I'm going to see?

    Thank you!

    Sorry! I found an answer here in the discussion:

    http://forums.Adobe.com/message/5835960#5835960

    So the problem will be solved in the final application, and it's just the scrolling in the Viewer.

    Thank you!

  • The right Shift key View 4 PCoIP/w and keypad does not work

    Hi all

    I'm having a weird behavior with the right shift key and the numeric keypad. This happens when you use view 4 with PCoIP. When you use RDP to connect to a system and using the console in vSphere.

    To illustrate the differences in the way he behaves, I typed the following string in an RDP session and a Console Session of vSphere.

    "@ @ 123 123.

    ^ Button '2' three times, three times, to left SHIFT + key '2' "123" on the top of the keyboard and 123 on the numpad + is offset to the right.

    You see that, while in RDP, the right shift key does not work and so that the console session the num pad behaves like the arrows or the end, pg DN (aka acting like numlock is turned off)

    VMWare tools are installed on the virtual machines in question. I tried to turn numlock on and off without a change in behavior.

    No I don't think that the numeric keypad problem has been reported.  But I've now reported.  I'll let you know if we have other questions.

  • View of rights only to the data store to the title of the specific group.

    I have a group of developers that I manage to their ESX host. However, I gave permissions to start/stop, snaps, etc. They showed their interest to be able to display information from the data store, so that they have an idea of how much space they use with all the clichés. So. What adjustment / settings do I need to check for them to get the rights from view.  I don't want that they have rights to the data center, there are other clusters, not to mention the developer cluster.  It would be very political, if I had to expose everything 'read only' under the view of data center.  Thoughts?

    Thank you

    It must give rights to the datacenter/host & clusters.  But this does not mean that we should give access to the cluster level.  You can ensure that you are not spreading the read access down to other objects.  Make sure, you can also add specific no access role on clusters under the root that you don't want them to see.

    -KjB

    VMware vExpert

  • API to view the output/log of the concurrent requests

    Hi all:

    I use EBS 11.5.10 (DB: 10r2)

    Is there an API I can call to view the output/log of a concurrent request?

    We have the APEX Oracle installed in the same database as our EBS and I am developing a report of the APEX, where user provide a competing request id and then click a button; then APEX calls some Oracle EBS API to extract the output/log for this id of the request file and open it in the browser automatically (assuming that / natural log of output is the text).

    Thank you!

    Kevin

    Hey Kevin,

    Here is an example of a sqlplus session:

    Set serveroutput on 10000;

    SQL > declare
    number of v_request_id;
    v_two_task varchar2 (256);
    v_gwyuid varchar2 (256);
    v_url varchar2 (1024);
    Start
    v_request_id: = 123456; (request identification number)
    Select profile_option_value
    in v_gwyuid
    of fnd_profile_options o, fnd_profile_option_values ov
    where profile_option_name = 'GWYUID. '
    and o.application_id = ov.application_id
    and o.profile_option_id = ov.profile_option_id;
    Select profile_option_value
    in v_two_task
    of fnd_profile_options o, fnd_profile_option_values ov
    where profile_option_name = 'TWO_TASK.
    and o.application_id = ov.application_id
    and o.profile_option_id = ov.profile_option_id;
    v_url: = fnd_webfile.get_url (file_type-online fnd_webfile.request_log, id-online v_request_id, gwyuid => v_gwyuid, two_task-online v_two_task, expire_time => 100);
    dbms_output.put_line (v_url);
    end;
    /

    http://appstierservername.yourcompany.com:8000/OA_CGI/FNDWRR.exe?temp_ID=12788080980 (number will appear here)

    PL/SQL procedure successfully completed.

    SQL >

    I hope this helps.

    Published by: DBA115102 on June 10, 2011 17:27

Maybe you are looking for