Need Solution to connect in - syntax PREVIOUSLY

Hello the Experts of Oracle

I need help in getting my desired results based on the attached example as I have my y tie my quesry. I don't want to use Xmlagg. I just want to go through the Connet-before any traditional way.

SQL * more: version 11.1.0.6.0 - Production Thu Jan 12 10:22:24 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
With partitioning, OLAP, Data Mining and Real Application Testing options


WITH TABLE_1 AS
(SELECT '123', '2' DOUBLE UNION TEST_INTENT REG_ID
SELECT ' 124 ', ' 2' REG_ID TEST_INTENT IN UNION DOUBLE
CHOOSE ' 125 ', ' 2' REG_ID TEST_INTENT OF UNION DOUBLE
CHOOSE ' 126 ', ' 2' REG_ID TEST_INTENT OF UNION DOUBLE
SELECT '127', '2' TEST_INTENT DOUBLE REG_ID)
TABLE_2 AS
(
CHOOSE ' 123 ', ' 10' REG_ID UNION TEST_CD DOUBLE
CHOOSE ' 123 ', ' 11' REG_ID TEST_CD OF UNION DOUBLE
CHOOSE ' 123 ', ' 14' REG_ID UNION TEST_CD DOUBLE
CHOOSE ' 124 ', ' 12' REG_ID UNION TEST_CD DOUBLE
CHOOSE ' 125 ', ' 10' REG_ID UNION TEST_CD DOUBLE
CHOOSE ' 125 ', ' 12' REG_ID UNION TEST_CD DOUBLE
CHOOSE ' 126 ', ' 10' REG_ID UNION TEST_CD DOUBLE
CHOOSE ' 126 ', ' 11' REG_ID TEST_CD OF UNION DOUBLE
CHOOSE ' 126 ', ' 13' REG_ID UNION TEST_CD DOUBLE
SELECT '127', '13' TEST_CD DOUBLE REG_ID)
TABLE_3 AS
(
SELECT '10' TEST_CODE, TEST_ALPHA 'BZ', THE OF ' CD_STATUS OF DOUBLE UNION
SELECT '11' TEST_CODE, TEST_ALPHA 'BB', THE OF ' CD_STATUS OF DOUBLE UNION
SELECT TEST_CODE '12', 'CA' TEST_ALPHA, THE OF ' CD_STATUS OF DOUBLE UNION
SELECT TEST_CODE '13', 'XX' TEST_ALPHA, 'A' CD_STATUS IN UNION DOUBLE
SELECT '14' TEST_CODE, TEST_ALPHA 'AA', THE OF ' CD_STATUS OF THE DOUBLE
)

Desired result is
REG_ID ALPH_STRING RN_CNT
123 AA, BB, BZ 3
124 1 CA
BZ 125, CA 2
126 BB, BZ 3
127 1

The RN_CNT is based on the TEST_INTENT = 2 column in TABLE_1 and ALPH_STRING is based on the s = CD_STATUS ' in TABLE_3

Here's my query

SELECT REG_ID, LTRIM (MAX (SYS_CONNECT_BY_PATH (TEST_ALPHA, ',')), ',') ALPH_STRING, count (RN_CNT) RN_CNT
Of
(
SELECT REG_ID, Q1. TEST_CD, RN_CNT, RN, Q1. TEST_ALPHA
Of
(
SELECT REG_ID, Q.TEST_CD, TEST_ALPHA,
ROW_NUMBER() OVER (PARTITION BY ORDER of the Q.TEST_CD Q.REG_ID) rn,
COUNT (Q.TEST_CD) ON RN_CNT (Q.REG_ID SCORE)
Of
(
SELECT R.REG_ID, I.TEST_CD, TEST_ALPHA
FROM TABLE_1 TO TABLE_2, I, TABLE_3 CT
WHERE R.REG_ID = I.REG_ID
AND R.TEST_INTENT = 2
AND I.TEST_CD = CT. TEST_CODE (+)
) Q
) Q1.
TABLE_3 CT1
WHERE Q1. TEST_CD = CT1. TEST_CODE (+)
AND CT1. CD_STATUS = THE OF ')
REG_ID GROUP
CONNECT BY REG_ID = PRIOR REG_ID
AND rn = rn + 1 ADVANCE
START WITH rn = 1
ORDER BY REG_ID


I'd appreciate any help in this matter.

Thanks and greetings

RB

Hello

Rb2000rb65 wrote:
Hello the Experts of Oracle

I need help in getting my desired results based on the attached example as I have my y tie my quesry. I don't want to use Xmlagg. I just want to go through the Connet-before any traditional way.

It is a tradition of using the best tool for the job. There is a tradition that goes back millions of years, to invent new tools for specific purposes (literally). What is the problem with XMLAGG? If it's the best tool for this job, why not use it?

In this case, CONNECT BY is a good tool to use for this job. Here's a way to do it:

WITH     got_rn     AS    -- Needed because rn has to be computed before CONNECT BY can be done
(
     SELECT      r.reg_id
     ,     CASE
              WHEN  ct.cd_status = 'S'
              THEN  ct.test_alpha
          END                    AS test_alpha_to_show
     ,     ROW_NUMBER ()     OVER ( PARTITION BY  r.reg_id
                             ORDER BY      CASE
                                       WHEN  cd_status = 'S'
                                       THEN  2
                                       ELSE  1
                                   END
                          ,             ct.test_alpha
                           )      AS rn
     ,     COUNT (i.test_cd) OVER ( PARTITION BY  r.reg_id )
                              AS rn_cnt
     FROM     table_1          r
     ,     table_2      i
     ,     table_3          ct
     WHERE     r.reg_id     = i.reg_id
     AND     r.test_intent     = 2
     AND     i.test_cd     = ct.test_code
)
SELECT       reg_id
,       LTRIM ( SYS_CONNECT_BY_PATH (test_alpha_to_show, ',')
          , ','
          )     AS alph_string
,       rn_cnt
FROM       got_rn
WHERE       CONNECT_BY_ISLEAF     = 1
START WITH     rn          = 1
CONNECT BY     rn          = PRIOR rn + 1
     AND     reg_id          = PRIOR reg_id
ORDER BY  reg_id
;

The trickiest part of this query is including all the rows in the query as a whole, but only including the lines with cd_status = the of ' in the aggregate string. It is easy to replace test_alpha with a NULL value in a CASE expression. Which could result in chains aggregated with additional separators, such as ', BB, BZ, 'or', FOO, BAR,'. We will need to use LTRIM (or siomething like him) to remove the delimiter 1 anyway. So, let's assign rn so that all NULL values to concatenate come at the beginning of the string.

Keep your code as simple as possible. In particular, do not use a subquery without reason. It is advisable to put comments in your code explaining the reaon for each auxiliary request. In this case, we only need 1 subquery, not 3.

When you use the SYS_CONNECT_BY_PATH to the aggregation of the chain, you will almost always want to use CONNECT_BY_ISELAF. Looks like you are using a technique of GROUP BY which was designed for Oracle 9, which had SYS_CONNECT_BY_PATH but not CONNECT_BY_ISLEAF. You say you have Oracle 11, so you don't need that.

Published by: Frank Kulash, January 12, 2012 12:42
Additional explanation

Tags: Database

Similar Questions

  • When you try to export images of Photos, I get an error message saying that I am unable to do it because I need an internet connection. That I have. Any ideas?

    When you try to export images of Photos, I get an error message saying that I am unable to do it because I need an internet connection. That I have. Previously, I was able to simply select, make drag & drop in a folder open access to change. Any ideas?

    When you try to export images of Photos, I get an error message saying that I am unable to do it because I need an internet connection.

    Could something intercept Internet to iCloud photo library and cause delays? A firewall or Antivirus filter?  Have you recently installed software?

  • Do I need an internet connection to play music from Apple?

    Hello, I will be visiting by air soon, I need an internet connection to enjoy the music, that I loaded into my Apple iPhone music Playlist? Thank you.

    Start here:

    Add music catalog to Apple's music to your library on your iPhone, iPad, iPod touch, Mac, or PC - Apple Support

  • I need help to connect my iPhone apps on El Captian Office

    I need help to connect my iPhone apps on El Captian Office

    Without knowing exactly what you're trying to do, this article from Apple can help:

    Continuity allows you to connect your iPhone, iPad, iPod touch and Mac - Apple Support

  • HP MINI 1000: HP MINI SYSTEM STOP FATAL ERROR. CNU9302RM6. Need password to connect!

    HP MINI SYSTEM STOP FATAL ERROR. CNU9302RM6. Need password to connect!

    Please someone SOLVE THIS PROBLEM. I HAV NOT OPEN MY PC one YEAR, please help me if you can?

    Good day!

    Boss!

    I have the password for you

    Please enter = e9lof17b4g

    Kind regards

    KNRK

    I work for HP

  • I need help to connect my macbook pro to my TV high definition. I just installed the latest update for el capitan, and now all of a sudden not work there.  I use a hdmi cable that has worked for me before.  Any suggestions?

    I need help to connect my macbook pro to my TV high definition. I just installed the latest update for el capitan, and now all of a sudden not work there.  I use a hdmi cable that has worked for me before.  Any suggestions?

    OS X El Capitan: use your TV as a monitor

  • Envy 13 - d005tu: I need an ethernet connection for my new HP envy 13 d005tu - y at - it an adaptor I can get?

    I need an ethernet connection for new HP Envy 13 d005tu - y at - it an adaptor I can get

    Hello

    Last week, I bought 2 of those on Amazon:

    https://www.Anker.com/products/A7514041

    And they work perfectly. Windows 10 will find the right driver for it or you can download from Anker.

    Kind regards.

  • Need solution for details of error below:-blue screen error BCCode 1000008e + BCP1:80000003 + BCP2:817855 A 8 + BCP3:8B9B9A54 + BCP4:00000000 + OS version: 6_0_6001

    get this problem in win 2 k 8 32-bit enterprose

    Need solution for the details of the error below: -.
    Blue screen error BCCode 1000008e + BCP1:80000003 + BCP2:817855 A 8 + BCP3:8B9B9A54 + BCP4:00000000 + OS version: 6_0_6001

    Hi SudhaArunachalam,

    Your question is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT Pro TechNet public. Please post your question in the TechNet Windows Server forum.

    http://social.technet.Microsoft.com/forums/en/category/WindowsServer/

  • What I need to be connected to my computer when windows backup is running?

    When you perform a backup of windows:

    You have to be logged into your account?

    Should the computer be on? I guess for this.

    When to perform a backup of multiple users, do they need to be connected as well?

    http://www.YouTube.com/watch?v=HZrX4Vb4ui4 Watch this video on how to use the windows XP backup.

    You must be logged in, and if you follow the instructions in the wizard, you will come to a point where you can choose to save everyone and they do not have to be connected.

    I hope this helps.

  • reinstalled windows xp on dimension B110 need drivers to connect to internet

    I recently reinstalled windows xp on dimension B110, but now I need drivers to connect to internet I can record on a disc and download on the computer is it possible? Could if so someone possibly post a link here for it so that I can get my poor computer again. Thanks in advance for your help.

    I recently reinstalled windows xp on dimension B110, but now I need drivers to connect to internet I can record on a disc and download on the computer is it possible? Could if so someone possibly post a link here for it so that I can get my poor computer again. Thanks in advance for your help.

    Hello and welcome on Microsoft Answers. Click on the link below to download the drivers for your computer. Please note that once you click on the download button you will be presented with a pop-up window asking you to choose a download method. You must choose "download with my browser. Let us know if you need more assistance.
    Drivers Dell Dimension B110

  • Im trying to download adobe pro xi and get an access denied message, need solution

    Im trying to download adobe pro xi and get an access denied message, need solution

    Hi Tom,

    Please try to download the app here: Download Adobe Acrobat products. Standard, Pro | DC, XI, X

    Thank you

    Abhishek

  • Startup to virtualization... What is the best solution to connect to ESXi?

    Hello;

    I started on virtualization and have some simple doubts on how to move forward... I hope someone can help me... (I hope I'm using the right forum to ask this question).

    I tested VMWare, and, so far, I made just a few steps:

    1.-j' VMWare ESXi (hypervisor) installed in a server.

    2. - I can connect to this server of VMWare ESXi with my Windows machine vSphere Client, and I created on the VMWare ESXi server a machine Suse Linux, I can use a lot of my windows machine and the software installed on it in vSphere Client.

    So far, everything is Ok, but I would go further:

    3 - I would like to be able to connect to this virtual machine for Linux on other computers, we (Windows, Linux)... And now, it's when I start to mix all the solutions and products, I prefer not to install the vSphere Client in all machines, because I'm not all machines to be able to administer virtual machines, but only to 'use ':

    I found there is a VMware View Agent, but I have failed to connect to my virtual Linux box, because after I installed on my Windows Machine, on the first screen, I put the IP address of my Linux virtual machine and get the message "unable to connect to...". ». I think it is because I have not installed the VMware discover the connection to the server... The truth is that to begin with, I don't plan to do more than 10 virtualized machines, therefore, I would like to avoid a solution where I have to install more software in addition to machines...

    ... And that's when my doubts:

    4. - what would be the most simple solution to connect to different machines to my newly created Linux box and 'use' VMware (not use)? (other VSphere Client to avoid someone administer my VM).

    5 - if I could use this solution on Windows and Linux? (Even better if I could use this solution to replace the operating system of the different machines and allow the machines just to start and connect to the virtual machines, because some machines are old, and I would like to re - use as a computer thinclient, in which, at the start, only will be apear icons of different machines to connect)

    Thank you!

    Alberto.

    Welcome to the community - just treat the VM as you would a physical machine - connect via RDP, SSH etc - which you could do with a Windows machine or lelievre

    See VMware Virtualize your desktops - that would be the solution to answer your question 5 that you could use a workstation as a terminal Wyse to allow a user to connect via AD and connect to their virtual office.

  • MUSE (2014.3) no longer works on my screen 1920 x 1080 please need solution

    The scaling of interface (2014.3) no longer works on my screen 1920 x 1080 please need solution

    Hello

    Please see the following forum post:

    Update the 2014.3 muse has a UI that is oversized.

    In the case where you are referring to a different question, kindly share a screenshot or error message.

    Concerning

    Sonam

  • 11.1.2 Essbase config: cannot choose "connect to a previously configured SS db.

    I opened a case with Technical Support but they are slow to respond and I've not found anything online research and I've already lost one day on this with a very tight deadline, and I know you're awesome, so I wanted to see if anyone has any ideas.

    Try to install 11.1.2 in a distributed virtual environment for the umpteenth time (always with the cool virtual servers each time) but when configuring Essbase, on stage "Shared Services Configuration and registry database connection associated with the instance of House" or radio buttons is gray however it won't really let me pick the a 'connect to a previously configured Shared Services database. When I click it, gets 'select case', but the small thin orange border that goes around the text for the radio actually jumps down and the border appears around the text of radio for "Configuration at the time of the 1st perform any operation of Shared Services database.

    The window will not let me click on next until what I fill in the details to set up a new database which of course, I don't want to do because I already have one that I use.

    I configured the SSP on my other server database and can successfully start and connect to Shared Services.



    O environment/Ss: Windows Server 2008 R2

    serverA (RDBMS server only):
    MSSQL Server 2008 R2
    To set EPM of mixed authentication Windows/SQL Server database
    Port is set correctly.

    serverB (Shared Services, Reporting, web apps):
    : Foundation Services Web Applications, Oracle HTTP Server, WebLogic application server
    Workspace
    Reporting and analysis: Application Web Framework, Framework and common libraries
    Creating interactive reports: Interactive Reporting Services
    Financial reports: Web Application, Financial Reporting Financial Service print server reports
    : Web Web Analysis Web Application
    Essbase: Application of 64-bit Essbase Administration Services, provider Services Web Application Web

    serverC (Essbase, environmental impact assessment)
    Essbase: Customer Essbase client, Client of the EAS, Studio, guest of the environmental impact study, Essbase Integration Services 64-bit, Essbase Studio Server, Essbase Server 64-bit Services
    (And, if necessary?: Foundation Web Applications, Oracle HTTP Server, WebLogic Application Server Services). But I don't configure Oracle HTTP Server with advice from John about that.




    Steps taken:
    serverA: created the new SQL Server database to use for all products (according to the documentation). Except that I create HIA database later.

    serverB: installed: Services Foundation: Foundation Services Web Applications, Oracle HTTP Server, WebLogic application server
    (while "chooses"Configuration at time 1 make operation of Shared Services database"and provided the correct server name RDBMS, port, name of database and SQL user name/pwd which has rights SQL Admin and area admin).
    (also defined a new domain for WebLogic, accepted the default settings and typed a password Admin).

    -Then set up these products successfully.

    -Then I successfully launched & connected services shared as an administrator.

    -serverB: then I went back to the installation on this server, this time by choosing all the stuff listed above web & apps Reporting.

    -Then set up these products successfully.

    Question: I have NOT configured Web server yet, apparently, you only after every other product on every single server configuration & installation, correct?

    -Restarted ServerB.

    serverC: installed Essbase products listed above.

    -Try to configure all these products and stuck on the screen where it won't let me choose "connect to a previously configured Shared Services database. Strangely, the screen behaves as described above.





    Windows services on ServerB:
    Hyperion Integration Services exists and is started.
    There is NO OTHER service Oracle/Hyperion, but I know that they should.

    Opens a session. ServerB has even not a directory "user_projects" unfortunately. Home\diagnostics\logs - I don't see anything remarkable in the newspapers it so that you can let me know what newspapers I should include here what files/servers? Thank you!

    I do turn install it logged in as my Active Directory account (I have admin server & SQL Server administrator rights).

    Installing assemblies are all together as requires it (I downloaded 1 file and extracts in this same folder). I am installing a network such as recommended in the documentation drive even if it seems strange.

    Installation on drive D on each server, using the home directories by default middleware etc.

    NOTE: On a previous attempt, I realized that I had no "Additional content" mined, while is extracted and now I can't get an Essbase Server installation configuration to save my life.

    Thanks in advance for any ideas!
    -Karen Smejkal

    You should be fine with a distributed installation, in many cases, essbase is sitting on a dedicated machine.
    I don't know why you receive questions, although with 11.1.2 If everything isn't exactly as it should be on the first configuration, it can end up being messy and relocation seems to be the best option.

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • I need help to connect my used ipod touch. The previous owner did not mention that I needed their icloud account to set up my account icloud to the ipod touch.

    I need help to replace a previous owners icloud/apple id. So I can replace with my apple/icloud id, we use it and I was ignorant, I needed previous owners apple id replace it with mine. The previous owner just told me how to reset or to put in recovery mode, but the previous owners apple id needs to turn off find my iphone settings. If I can replace with mine. The difficulty. Help, please!

    You run into the lock of Activation

    Find my iPhone Activation Lock

    If you can't have the previous owner to do

    Turn off find my iPhone Activation Lock

    then back for a refund since yo cannot use the device. Apple isn't going to help.

    If yo cannot come back, turn the unit into the police because it is likely, lost or stolen

Maybe you are looking for