Find all the possible combinations of grouping

Hello

I have a table of color names and must pick up all the possible combinations of color groups. For example, suppose I have the following table: -.
WITH colours AS (SELECT 1 id, 'red' colour FROM DUAL
               UNION ALL
               SELECT 2 id, 'blue' colour FROM DUAL
               UNION ALL
               SELECT 3 id, 'green' colour FROM DUAL)
SELECT *
  FROM colours
I don't want to get the following results:--
group  id
1       1
2       2
3       3
4       1
4       2
5       1
5       3
6       2
6       3
7       1
7       2
7       3
Could someone enlighten me please on how to extract this resultset?

Published by: tri_harder on April 30, 2010 13:42 updated spelling

With Oracle 9i:

  1  WITH colours AS
  2       (SELECT 1 ID, 'red' colour FROM DUAL
  3        UNION ALL
  4        SELECT 2 ID, 'blue' colour FROM DUAL
  5        UNION ALL
  6        SELECT 3 ID, 'green' colour FROM DUAL),
  7       m AS
  8       (SELECT COUNT(*) AS max_level
  9         FROM colours)
 10  SELECT   GROUP_ID,
 11           SUBSTR(sp, INSTR(sp, '-', 1, lvl) + 1, INSTR(sp, '-', 1, lvl + 1) - INSTR(sp, '-', 1, lvl) - 1) AS ID
 12      FROM (SELECT     ROWNUM AS GROUP_ID, ID, SYS_CONNECT_BY_PATH(ID, '-') || '-' AS sp
 13                  FROM colours
 14            CONNECT BY ID > PRIOR ID),
 15           (SELECT     LEVEL AS lvl
 16                  FROM m
 17            CONNECT BY LEVEL <= max_level)
 18     WHERE lvl < LENGTH(sp) - LENGTH(REPLACE(sp, '-'))
 19* ORDER BY GROUP_ID, ID

  GROUP_ID ID
---------- ------------
         1 1
         2 1
         2 2
         3 1
         3 2
         3 3
         4 1
         4 3
         5 2
         6 2
         6 3
         7 3

URS

Tags: Database

Similar Questions

  • Need to find all the possible child records with SQL

    Hello - I am trying to find a way to solve the following with a sql statement:

    I have a table with columns, and the following values:
    Trans_Id   Parent_Trans_id
    1             null
    2             1
    3             2
    4             3
    So basically, 1 is the master parent and I need to bring all ranks, because they are all ultimately originated due to 1. How to write sql code to return all possible levels associated with parent_id = 1?

    I hope I'm communicate that effectively do this, but please let me know if it needs to be clarified.

    Any help is greatly appreciated...

    Thank you
    Christine

    Hi, Christine.

    I think you want to CONNECT BY, something like this:

    SELECT     *
    FROM     a
    START WITH     trans_id      = 1
    CONNECT BY     parent_trans_id      = PRIOR trans_id
    ;
    

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}
    You will find the answers better faster if you always provide this information whenever you post a question.

  • How is possible to create a smart collection to find all the photos that are not belongs to any collection?

    Hello

    How is possible to create a Smart Collection to find all the photos are not belongs to any collection?

    "Yesterday I was importing a lot of photo when my camera battery died then I succeeded him and continued to import without thinking that the previous import collection literally means" previous import. "

    So I need to find a way to create a smart collection that will reveal all the photos that do not belong to any collection.

    I solved the problem with a workaround is creating a collection based on the date of the photo which worked well, but must be nice to have a more general collection to find all the photo that are not from the collections.

    Thanks in advance,

    Marco.

    Another way to do

    1. Select all photos in the catalog

    2 dismiss a color label

    3. go to collections and multi select all your collections (ctrl)

    4. select images and give them a color

    5. return to the catalogue

    6. filter by color label - No

  • Where can I find all the drivers Win 7 for Satellite L40 - 14F

    Hi all
    Find all the drivers for L40 laptop model 14F for windows 7 OS? Is that someone has installed this OS? Is it possible to have some problems during installation? Thank you very much.

    Most of the new models is Win8 or Win10 models, they won't get Win7 drivers available.

  • How can I find all the plugins in the firefox browser

    HI I was wondering if I could ask a question how can I find all the installed plugins in the firefox lasted I would like to be able to know if, for example, if the shockwave plugin is updated and which version is currently installed in the firefox browser lasted.

    Thank you

    Hello Funny78, type Subject: addons in the address bar and then select plugins, add-ons manager opens and you can see the last version of the plugins (and other info), now click on the click to see if your plugins are up to date and see if it is.

    Thank you

  • Firefox prompts to save passwords of websites. The key to the Password Manager icon appears on the left side of the address bar, but the corresponding window asking if I want to save the password or not, does not appear. I tried all the possible solutions

    I installed the latest version of Firefox on my laptop (Windows 7 Professional 64-bit). The thing is that firefox prompt to save passwords of websites. I'll explain you a little more away with an example: suppose I load www.gmail.com. When I login, the password manager key is displayed on the left side of the address bar, but the corresponding window which would ask if I want to save the password or not, does not appear. I tried all the possible solutions. It is true that when I restart firefox with disabled modules (safe mode), password manager works fine. But I don't really use Add-ons that could prevent firefox to save passwords. I disabled all add-ons and ran firefox in normal mode, but the password manager does not work yet. Please keep in mind that I tried everything and that any post not published so far describes a similar problem to mine case. Consider that I have the same I have configured the entire system from the beginning. The problem appeared again from the first time I launched firefox. At that time, I had not installed any antivirus software and there is no add-on with firefox. Hope someone can give me a valid solution...

    Start Firefox in Firefox to solve the issues in Safe Mode to check if one of the extensions or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > appearance/themes).

    It is possible that there is a problem with key3db and signons.sqlite files that store the encrypted names and passwords in Firefox.

    Rename signons3.txt and signons.sqlite files in the Firefox profile folder.

    You can add .old files (key3.db.old and signons.sqlite.old) names or move them to another folder to make it possible to cancel the action.

    You must define a new master password after renaming or removing the signons3.txt and all the currently saved passwords are lost.

    If that worked, then you can delete the renamed files that are no longer needed.

    See:

  • Satellite Pro L40 PSL43E I need to find all the drivers XP

    I need to find all the XP drivers for this laptop in particular. Any ideas where I can find them. on this site, I get only the ' how downgrade "Pease help ASAP.

    If these drivers are available, you will be able to find these drivers on the European driver Toshiba page.

    If the drivers are not available on the European driver Toshiba page, the pilots were not released.

    But I have a suspicion; I found some XP for Sat L40 series drivers. Some series supports the same devices and so the drivers should work also.
    Check some unique XP from different L40 series drivers and maybe he would go.

    Ciao

  • Where can I find all the drivers for Tecra 8200

    Where can I find all the drivers for a Toshiba tecra 8200 PIII750/20/14 t/D/LM/W - I searched for drivers (all drivers) this Labtop can enyone please help me :)

    Got Windows XP:

    Post edited by: Rullings

    Hello

    Have you checked the European driver Toshiba page?
    This site contains all the necessary drivers for Win95, Win98, Win98SE, Win XP, ME, W2k.

    Only Vista drivers are not available for this oldie

    Check it!

  • How to find all the Subvi value changes to a control inside a cluster?

    I have a question I've had brewing for many years now, and as of today, this issue has become less philosophical for me now that I have a VI project with hundreds of screws in there to work through... If I have a cluster which is passed between/through several subVIs, is there a way to find all reads/writes to a particular control within this cluster? For example, if I use a global variable, I can find all the instances where this variable has been changed. Several times, a cluster is used to pass data instead of lots of global variables, but I know not anyway quickly find where specific parts of the latter are read or written in subVIs. Global variables becomes a headache when they are too many of them fly around, but I can't keep track of reads/writes in bunches without manually looking through a few screws hundreds that take in the cluster. Is there a function for this that I'm not aware of? I hope that this question/problem of logic. This may prompt a discussion of architecture, which I would be happy, because I will need to build projects of this scale in the future, but I think also completely stuck when the clusters are used (by me or others) to pass data autour. Thank you! John

    If you ungroup by name and bundle by name, just do a search for text to the name of the control.

  • How to find all the my post anywhere in the forum?

    Desktop HP Pavilion Elite HPE - 110 t... Operating system: Windows 7 Home Premium

    .

    Several months ago (maybe even a couple of years), I discovered that backup/restore are not created.  At this time I posted a question here.  Which lead to a very long series of back & suite assignments between myself & a answering machine (name?) & Finally I planned a daily task to create backup/restore points.  I saved the instructions into a Word document on my computer, but now I can't find them.

    .

    I just found out that there is still no restore point, even though the Task Scheduler shows that he ran this morning @ 02:00.

    .

    I just searched (I thought that all the forums here) for my username (jarhtmd) & only found 4 son, none of whom was what I was looking for.

    .

    How to find all the my post anywhere in the forum?

    Hello:

    Click on your user name to access your user name page.

    Then click recent posts by jarhtmd. Click on view all.

    Maybe it's the post you were talking about.

    http://h30434.www3.HP.com/T5/desktop-operating-systems/scheduling-system-protection-backup-restore-points/m-p/647911#M32431

    Paul

  • How to find all the old files and documents on the hard drive

    Original title: how to find a file

    How to find all THE old files and documents on the hard drive

    Hello

    -Are the old hidden files?

    I recommend you follow the steps in these articles for help.

    Show hidden files
    Find a file or folder

  • I have just re-installed Windows Vista and I can't find all the files he supposedly saved.

    I recently reinstalled vista (yes I know I should have bought mac) in any case I can't find all the files I've supposedly saved. any ideas? Thank you

    original title: Reinstall vista

    Hello

    You don't say how you have reinstalled or how or where or by which program or process, you saved your data...

    A relocation normally will wipe away the old operating system and all data during the resettlement process.

    You can try this free program to see if it can recover your data:

    http://www.Piriform.com/Recuva

    See you soon.

  • HP Pavilion n072sy-15 Notebook PC - where to find all the drivers for Windows XP and Windows 7

    Who knows where to find all the drivers for Windows XP and Windows 7 for HP Pavilion n072sy-15 Notebook PC?

    Hello:

    XP will not install or run on a PC with an Intel 8 series chipset, so you need not be concerned with finding drivers.

    Here is the link to a template that you can use the W7 x 64 bit drivers from.

    When you install the graphics drivers, first install the Intel HD graphics driver, reboot and then install the graphics driver nVidia.

    DO NOT USE ALL DOWNLOADS OF BIOS OR FIRMWARE FROM THIS LINK

    http://h10025.www1.HP.com/ewfrf/wc/softwareCategory?OS=4063&LC=en&cc=us&DLC=en&sw_lang=&product=6521374

  • I am unable to find all the programs and features in win7 as I want to uninstall yahoo messenger

    I am unable to find all the programs and features in win7 as I want to uninstall yahoo messenger

    That's what Yahoo have to say - http://help.yahoo.com/kb/index?y=PROD_ACCT&page=content&id=SLN408&actp=lorax&locale=en_US

    If the control panel is set to display the categories - programs - programs and features

    If the control panel is set to display the icon - programs and features.

    Yahoo Messenger should be in this list.

    If you say programs and features isn't in the Panel or Yahoo Messenger is installed, but not in the list, then something else is wrong.

    Try in "search programs and files" type "programs and features" (without the quotes). In the results list, you should see "programs and features" near or at the top of the list, click it.

    If Yahoo messenger is installed and will not uninstall, see the above link to the bottom of his page.

  • How to find all the table names in all modules in EBS R12?

    How to find all the table names of all the modules in EBS R12?

    In addition, you can go to http://etrm.oracle.com, you select the version of the EBS, select "FND Data" or "S/n data", select the Type of the object TABLE and you will get all the tables of EBS in module.

Maybe you are looking for

  • New Comcast Modem does not work with my Airport

    I got a modem from comcast yesterday to replace the two separate modem, I had. One was for the phone, the other was for the internet. One that has been for the internet, I've owned and the phone, one was theres. I just disconnected the internet one a

  • How to remove HP protect tools to anti-theft

    I'm moving from Win7 to win 10 on my 8560w. The preparation of Windows 10 utility says that I must remove HP Protectools. But remove HP Protectools fails because first I remove "HP theft recovery software". I know what actially LowJackPro (\Program F

  • Sysprep and SIDS

    I create templates for Windows 2008 R2 the final step of each creation is a /oobe/shutdown sysprep. Once the template is cloned and booted up, we do an other sysprep /oobe /reboot. The second sysprep is supposed to be in order to change the SID... Qu

  • PIXMA MG3250: Print odd sequence

    When I want to print some pages, I insert in the print on the PC (for example) menu "1-4" or "1,2,3,4", the printing sequence is always back that is 4, 3, 2, 1" Can I change this to the NORMAL sequence?

  • Sansa crashes WMP after upgrade of the motherboard

    Hello I recently updated my Windows Vista x 64 - motherboard, processor, video card system - and since then, I had problems with my Sansa.  Now, when I start Windows Media Player 11 (WMP) and then plug in my 8 GB Sansa, WMP closes, with the dialog bo