FIX for generate lines of separation and GROUPING

Oracle 11g Release 2

I need to do this in SQL, not front-end app.

CREATE TABLE tab2
( rule_order   varchar2(25)
 ,part_type_id varchar2(25)
 ,position_id  varchar2(25)
 ,note1        varchar2(500)
 ,group_id     varchar2(25)
 ,part_desc_id varchar2(25)
 ,line_cd      varchar2(25)
 ,checkup      varchar2(25)
)
/

insert into tab2
values(7,'AB777','LEFT',null,48,98,'ABC','NO')
/

insert into tab2
values(12,'CC789',null,null,48,98,'EF3','YES')
/

insert into tab2
values(14,'FFY3','REAR',null,50,99,'Y3Y','NO')
/

insert into tab2
values(17,'789D',null,'escape',52,107,'CAB','NO')
/

insert into tab2
values(19,'65ACD',null,null,52,107,'FAB','NO')
/

insert into tab2
values(20,'888EF','FRONT','REMAN',52,107,'CH7','YES')
/

insert into tab2
values(22,'760DB',null,null,72,12,'DEG','YES')
/

insert into tab2
values(25,'535AF','FRONT',null,72,12,'BBB','YES')
/

commit;

select * from tab2;

RULE_ORDER   PART_TYPE_ID   POSITION_ID    NOTE1           GROUP_ID  PART_DESC_ID LINE_CD   CHECKUP
------------ -------------- -------------- --------------- --------- ------------ --------- ---------
7            AB777          LEFT                           48        98           ABC       NO
12           CC789                                         48        98           EF3       YES
14           FFY3           REAR                           50        99           Y3Y       NO
17           789D                          escape          52        107          CAB       NO
19           65ACD                                         52        107          FAB       NO
20           888EF          FRONT          REMAN           52        107          CH7       YES
22           760DB                                         72        12           DEG       YES
25           535AF          FRONT                          72        12           BBB       YES



NEED OUTPUT:

RULE_ORDER PART_TYPE_ID POSITION_ID NOTE1   GROUP_ID PART_DESC_ID LINE_CD CHECKUP
---------- ------------ ----------- ------- -------- ------------ ------- -------
         7        AB777        LEFT               48           98     ABC      NO
        12        CC789                           48           98     EF3     YES
         -
        17        789D              escape        52          107     CAB      NO
        19        65ACD                           52          107     FAB      NO
        20        888EF       FRONT REMAN         52          107     CH7     YES
        -
        22        760DB                           72           12     DEG     YES
        25        535AF       FRONT               72           12     BBB     YES

RULES:

Only interested in cases where the combination of GROUP_ID/PART_DESC_ID has two or more records.

Then GROUP_ID/PART_DESC_ID 50/99 is not included in the output.

Need to have a line empty (with a dash in RULE_ORDER) when GROUP_ID/PART_DESC_ID change

########################

I tried to use GROUPING and CUMULATIVE, but I do not get the desired result.

WITH  data
AS
(  SELECT rule_order, part_type_id,position_id,note1,group_id,part_desc_id,line_cd,checkup,
          CASE 
              WHEN GROUPING(part_desc_id) = 0
              THEN rule_order
              ELSE '-'
          END   txt
   FROM (
            select rule_order, part_type_id,position_id,note1,group_id,part_desc_id,line_cd,checkup,
                   COUNT(*) OVER (PARTITION BY group_id,part_desc_id) cnt
            from   tab2
         )
   WHERE
            cnt >= 2
   GROUP BY
            group_id, part_desc_id, ROLLUP ((rule_order, part_type_id,position_id,note1,group_id,part_desc_id,line_cd,checkup))
)
SELECT *
FROM   data
order by
       group_id, part_desc_id,part_type_id,position_id ;
       
RULE_ORDER   PART_TYPE_ID   POSITION_ID    NOTE1           GROUP_ID  PART_DESC_ID LINE_CD   CHECKUP   TXT
------------ -------------- -------------- --------------- --------- ------------ --------- --------- -------------------------
7            AB777          LEFT                           48        98           ABC       NO        7
12           CC789                                         48        98           EF3       YES       12
                                                           48        98
19           65ACD                                         52        107          FAB       NO        19
17           789D                          escape          52        107          CAB       NO        17
20           888EF          FRONT          REMAN           52        107          CH7       YES       20
                                                           52        107
25           535AF          FRONT                          72        12           BBB       YES       25
22           760DB                                         72        12           DEG       YES       22
                                                           72        12

It's not printing a '-' in RULE_ORDER and it must have the value NULL, GROUP_ID and PART_DESC_ID for the dividing line.

Hello

Rather than use the CUMULATIVE (or GROUPING SETS) fix for this, you should consider a UNION.  A branch of the UNION produced the data rows and the other lines of separation.  Foor example:

WITH got_groups AS

(

SELECT tab2.*

, COUNT AS group_cnt (*) OVER (PARTITION BY group_id, part_desc_id)

, DENSE_RANK () OVER (ORDER BY group_id, part_desc_id) AS group_num

Of THE tab2

-WHERE - if you need any filtering, it's where he's going

)

full_data AS

(

SELECT *.

OF got_groups

WHERE group_cnt > 1

UNION ALL

SELECT '-', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, group_num

OF got_groups

WHERE group_cnt > 1

GROUP BY group_num

)

SELECT rule_order, part_type_id, position_id, note 1

group_id, part_desc_id, line_cd, health check

OF full_data

WHERE rule_order <> '-'

OR group_num > 1

ORDER BY group_num

, LPAD (rule_order, 25)

;

Output:

BIRD BIRD

GROUP POSITION RULE_ DESC_ LINE_ TYPE_

ORDER ID _ID NOTE1 _ID ID CD CHECKUP

----- ----- -------- ---------- ----- ----- ----- -------

7 AB777 48-98 ABC NO. LEFT

12 48 98 EF3 CC789 YES

-

17 789 D escape 52 107 CAB No.

19 65ACD 52 107 NO. FAB

20 FRONT REMAN 52 107 CH7 888EF YES

-

22 72 12 DEG 760DB YES

25 535AF BEFORE 72 BBB 12 YES

This query generates only the lines of separation of G - 1 when there are groups of G, since you only want separators between groups, not before the first or after the last group.

Tags: Database

Similar Questions

  • How to fix the missing lines of text and formatting lost, hyphenated words and text disturbed flow, after the conversion of PDF in word doc to allow editing? using WPS office application on Android Galaxy tablet. tried Polaris app and got a blank document

    How to fix the missing text and updated lines shaped, hyphenated words and patterns disrupted, lost after export PDF document to word doc to allow editing? using WPS office application on Android Galaxy tablet. tried Polaris app and got a blank document.

    Thank you!

    Hi Spider,

    Adobe Acrobat on mobile devices can be used for editing. I will suggest you to perform the task on PC or Mac.

    Thank you

    Abhishek

  • Fix for content page styles?

    Hello

    I am a novice user of IDcs6. I formatted a book with several chapters. on the content page, I want to have two fonts of different sizes in the same paragraph. for example the chapter number and title in 1 fonts size 1 and the subtitle on the following line in the font and size 2, followed by a broader attack before the next chapter title. My original text is in Word, but ID won't import the line spacing in Word or two fonts. What Miss me? I have class in the book, but can not see relevant lesson. Is it available in the styles of character and paragraph or make separate for each line text boxes and interest? Anyone know a YouTube tutorial that might help?

    I don't use automatic TOC - six onlt entered and the fonts are different as the chapter headings. I insert the page numbers manually.

    Steve

    Thanks, I'll see nested styles...

  • Trying to install Canon MP250 with a Windows XP Professional version 2002 service pack 3 OS.___Receiving several associated messages.___Fix error Printer Spooler app it yourself and Fix for me the MS site options have failed. ___

    My OS is Windows XP Professional version 2002 service pack 3

    Spooler subsystem app has encountered a problem and needs to close.

    Spoolsv.exe - application error
    the instruction at "0 x 00300000" referfenced «0 x 00300000» memory  the memory could not be "read".  Click ok to complete the program, click Cancel to debug the program.

    When I try to manually restart the print spooler, I get the error message:

    script error Internet explorer
    an error has occurred in the script on this page
    line: 1
    Char: 1
    error: unspecified error
    Code: 0
    URL:RES://c:\Windows\System32\mmcndmgr.dll/views.htm

    I tried all the fix it you suggestions on the site of MS (by removing printers, printers spool, drivers, driver files, editing the registry...)  Still the same problem resurfaced.  I even downloaded a registry cleaner to give a shot and no progress.  The only thing that I have not been able to do is, log in Safe Mode, because doing the newspaper in tells me that my password/login is incorrect (also a great mystery)
    I also ran all the fix for me programs offered - no. RESULTS

    I am extremely frustrated, I should share the printer and try another brand.  Who count? Help, please

    Hello Demars_will,

    Thank you for your message.  There are a few known bugs for this problem.  Try these two steps:

    Try first to this step:
    Put your XP CD in the CD drive.
    Click "Start" > click "Run" > Type EXPAND/r 'TheCDDriveLetter' \i386\SPOOLSV. EXE C:\Windows\System32 and press "Enter."
    Click "Start" > click "Run" > type SPOOLSV. EXE/install and press "Enter."

    Click 'Start' > right click on 'My computer' > select 'manage '.
    Click the (+) sign next to Services and Applications, under Select 'Services '.
    On the right, locate and double-click "Print Spooler" > auto value startup > select 'Start' > click 'Apply and OK.

    A test to see if the spooler has begun.

    If this is not the case, click HERE for a registry change that may solve your problem.  There are a few different registry changes, I don't know if you have tried this one or not.

    Change the settings of the REGISTRY can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the REGISTRY settings configuration can be solved. Changes to these settings are at your own risk.

    Please let us know if it did or did not help to solve your problem.

    Soon Jason Microsoft Support Engineer answers visit our Microsoft answers feedback Forum and let us know what you think.

  • How to choose different lines for a single sale order and ship individually

    I have a customer order of lets say 10 broadside of this same article for quantities of 10 each which means 100 quantities.

    When I use the release sales order form it will take the entire order and forward it.

    But I need to take the line and then generate a delivery against it and then to ship and invoice it.

    Need to know how to do this

    You can take different lines for a single sales order and ship individually using FORM of TRANSACTION of DELIVERIES.

    Navigation: OM RESP > order management > shipping > Transactions

  • Align 45 does not... Some opinions, I cannot draw a line at 45 and 90 degree angle with a line (for example to draw a straight line with SHIFT tool, select and line maintenance, form does not hang at increments of 45 as it was by default) it Note still wo

    Align 45 does not... Just noticed I can't align a line at 45 and 90 degree angle with a line (for example to draw a straight line with SHIFT tool, select and maintaining line, shape is not hang at increments of 45 as it was by default) it notes still works with forms & text etc, but not with a straight line. Having downloaded the latest January 14, 2016

    Last update fixed this Glitch, Illustrator please :-)

  • my iphone was droppped and custom lights, but you can which is a light on it as if it is in standby mode. is there any fixes for this.

    my iphone was droppped and custom lights, but you can which is a light on it as if it is in standby mode. is there any fixes for this.

    Try to do a reset. Hold home and buttons power together for 30 seconds or until you see the Apple logo.

    If that does nothing, there's a chance that the LCD connector has partially disconnected. Although it is most likely your LCD is damaged.

    Apple may offer a replacement of the screen. You must check in your country, how much they charge.

    Alternatively, you can look for a reputable independent repairer who can replace the screen for you. This means waive all the Apple warranty services. But it's a bit less expensive for a C. 5 If you go this route, choose a repairer who offers a guarantee of 6 to 12 months. And don't go with the cheapest.

  • Fix for FaceTime and iMessages on El Capitan "an error has occurred during authentication"

    There will be a fix for this error? It's very frustrating, I'm hoping he gets patched as soon as POSSIBLE. I tried everything suggested on the forums of Apple and you have found no solution. It used to work fine until I updated the software on my Macbook.

    You must post a detailed description of what you're trying to do and and what's happening, or nobody can help you solve your problem.  There are millions of users of iMessages on El Capitan, which do not face any questions at all, so the problem is almost certainly on your end.

  • LabVIEW allows to read an Excel file to a control and add a checkbox for each line

    As say the topic, I need to use labview to read an excel file and show it in a control, such as mclb; I should add a checkbox for each line then allow me to choose the line I want. What should I do? Thank you very much.

    guiming wrote:

    I can read an Excel file to a spreadsheet, but I have no idea how to do to add a checkbox for each line.

    Sometimes, all you need to do is Google. https://decibel.NI.com/content/docs/doc-25000

    http://www.labviewing.com/check-box-in-multicolumn-ListBox/

  • LV 2011 development environment and prompt to install the fix for LV 2012 RT Module f1?

    I have a LV 2011 development environment configuration, including RT I get a message that there is an urgent fix for RT 2012 LV available; See attachment.  This machine of development must remain the LV 2011; This patch must be installed?  Thank you.

    Matt

    As stated in the notification message, you see this update because you probably have another component which released LabVIEW RT 2012 - NOR-RIO 12.0, WSN 1.4 or Fieldpoint 6.0.11.  It was to fix a specific problem in 2012 of LabVIEW, which hit the RT, so if you haven't installed LabVIEW 2012 then the patch will be neither harmful nor helpful to you; However, files of Framework Setup OR RIO, WSN and Fieldpoint for RT should be updated to be compatible with changes in LabVIEW (and so you probably installed component that has an update is available, even if 2012 LabVIEW itself is not installed).

    -Danny

  • Why Vista WMP can't play .asf files and why MS has not created a fix for this?

    Why Vista WMP can't play .asf files and why MS has not created a fix for this?

    Hi pdaamckechnie,

    The ASF Format (Advanced Systems) is the preferred Windows Media file format. With Windows Media Player, if the appropriate codecs are installed on your computer, you can play audio content, video content, or both, that is compressed with a wide variety of codecs and that is stored in an .asf file.

    You can check the link below for more information on the types of media files that supports Windows Media Player
    Information on the types of media files that supports Windows Media Player
    http://support.Microsoft.com/kb/316992

    See the link below for more information on codecs.
    Codecs: Frequently asked questions
    http://Windows.Microsoft.com/en-us/Windows-Vista/codecs-frequently-asked-questions

    Please post back and let us know if it helped to solve your problem.

    Kind regards
    KarthiK TP

  • fax from Windows 7 on x 64 gives script error, line 2107 1 tank invalid procedure call error or argument, res//ieframe.dll/preview.js URL, know a fix for this?

    fax from Windows 7 on x 64 gives script error, line 2107 1 tank invalid procedure call error or argument, res//ieframe.dll/preview.js URL, know a fix for this?  Worked very well for server 2008r2.

    Hello

    1. you have recently installed Internet Explorer 9?

    If Yes, consult the following link:

    http://social.technet.Microsoft.com/forums/en-us/ieitprocurrentver/thread/b50f867e-3f67-4714-856A-59891fced4b9

    Let us know if the problem is solved or not.

  • Additional portal for creating users and groups in OBIEE.

    Good afternoon everyone

    We are facing a situation where a resource by another company needs to create and manage their own users who will access OBIEE.

    That means that for the moment we have create users in Weblogic, but we cannot provide the resource with access to weblogic due to many other services running in the Weblogic causing a safety hazard.

    My question: is there another way, we can provide access to this resource through a portal that will only be able to manage the users and groups that will access OBIEE and not be able to view all other settings?

    Concerning

    Benoit

    Hi Benoit,.

    Cool, can you close the thread if it is right for you? Currently, it is still marked as

    This issue is no answer.

    If you have detailed follow-up questions (which I think you will to the BISQLProviders) you can make a custom thread and we will deal with this matter else on its own.

    See you soon

  • I currently have a creative cloud with an e-mail account, however I have a behance with an e-mail account that I have had for many years (even Adobe and Behance made before part of the same group). Can I combine these two accounts into one?

    I currently have a creative cloud with an e-mail account, however I have a behance with an e-mail account that I have had for many years (even Adobe and Behance made before part of the same group). Can I combine these two accounts into one? I want to use the account that I pay cloud Creative if I can use the new portfolio feature.

    Thank you.

    This is an open forum, not Adobe support... below to connect with Adobe personnel to help

    While the forums are open 24/7 you can't contact Adobe support at any time

    Chat support: Mon - Fri 05:00-19:00 (US Pacific Time)<=== note="" days="" and="">

    Don't forget to stay signed with your Adobe ID before accessing the link below

    Creative cloud support (all creative cloud customer service problems)

    http://helpx.Adobe.com/x-productkb/global/service-CCM.html

  • Update for the application manager has failed. Impossible to reinstall. Cannot use my apps. Get the 43 error message when I try to re - install. Is it possible to fix this problem without a wipe and load?

    Update for the application manager has failed. Impossible to reinstall. Cannot use my apps. Get the 43 error message when I try to re - install. Is it possible to fix this problem without a wipe and load?

    Error 43 https://forums.adobe.com/thread/2070909

Maybe you are looking for

  • 13 new tab Firefox opens the page with the error "page is not valid.

    Installed version Firefox 13. New tab button, new tab or Ctrl-T file results in message: The address is not validThe URL is not valid and cannot be loaded. The Web addresses are usually written as Http://www.example.com/Make sure that you use slashes

  • Game compatibility

    Why your list of games that are windows 7 is compatible if small and with games that I have ever heard.  What is the list of incompatible biggest games? and why don't you show it. If you do not provide a list of popular games that are compatible, how

  • Toshiba laptop A105-S1013 msg device not recognized USB.

    will not recognize usb keys. right now, I don't have connection capabilities as I am waiting for AT & T to connect with DSL. tried to connect to a wireless Belkin device but the USB does not recognize the he or the Belkin drivers on another device. f

  • 150

    I have an Officejet 150, my Samsung S5 won't come looking for the booth to connect to the printer. I downloaded HP eprint and photoshare or connects to the printer.

  • Error message: cannot copy... Failed to create the directory or file.

    I get the Error Message ' cannot copy (a file USB Store n Go): failed to create the directory or file.»  All of a sudden I started getting error message is when I tried to copy to the USB mass storage: "F:" copy on the removable key worked for a proo