SQL to get first level parent counties only

11g,

Hello world

I have a table like

Create the table TempEmp

(number of emp_id,

emp_name varchar2 (100),

number of mgr_id,

report_submit_status varchar2 (1)

)

Insert into TempEmp values (1, 'xxxx', 2, 'Y');

insert into Tempemp values (2, 'YYYY', null, 'n');

insert into TempEmp values (3, 'vvvv', 2, ' don't);

insert into TempEmp values (4, 'tttt', 1, ' only)

I need to show the output of the first level below the EMP is entered and the counts where status = ' not grouped by them.

For example,.

If you run the query for emp_id 2, 1 and 3 reporting directly to him. and the 4-1 statement. If the output should be

County Assessor first_level emp_id where report_submit_Status is N

1                                                                              1

3                                                                               1

If I ran the sql of emp_id code 1, the output would be

County Assessor first_level emp_id where report_submit_Status is N

4                                                                              1

That way the hierarchy could be up to any level, as in an organization.

Any help would be appreciated

Thank you!

Ryan

Hello

According to your specific needs, here's a way:

WITH got_first_level_emp_id AS

(

CONNECT_BY_ROOT SELECT emp_id LIKE first_level_emp_id

OF tempemp

WHERE report_submit_status = ' don't

START WITH mgr_id = 2 - or whatever the desired value

CONNECT BY mgr_id = emp_id PRIOR

)

SELECT first_level_emp_id

COUNT (*) AS count_n

OF got_first_level_emp_id

GROUP BY first_level_emp_id

;

Tags: Database

Similar Questions

  • How to release the source code (only) for first level VI?

    Hello

    I develop an add-on for an application that I have. The demand is large (more than 1,500 VI) and the screws are set up to compile with for most of the default settings (there is a first level VI, some with visible front, most of them are not visible).

    The customer wants that source code for the work that I do, and he will use the many existing Subvi. The addon itself will be a Subvi (I have a Main.vi that basically opens 'front' and it is a new screen). The sub - VI existing basically make data collection and treatment, and the new code will perform additional processing and have a nice GUI for existing code. The customer wants the source so that they can make changes as needed.

    Is there an easy way to simply provide the source for the first level VI? Basically, I want to give them M.vi, where M.vi name n.vi, o.vi... etc, but o - z.vi should be non-free. In addition, M.vi is called by Main.vi, which opens A screens - M.vi

    One option is to copy the entire application, then open each sub - VI and save it without Source Code. But with so many files, this seems like a bad idea. So, I also maintain two applications.

    Good ideas out there? It seems if easy in other languages (using object files) it looks like there should be a solution here I don't see... Thank you!

    rnelsonee wrote:

    Ah! I completely forgot to Save with Options. It's been so long that I had to deal with this type of problem.

    OK, to ensure that:

    I opened my first level VI, saving Options with-> apply the password (or remove diagrams) and then give it to them. I also provide a normal backup of their VI, with source.

    I still about 100 screws which are called dynamically are not part of the VI treeand I would still have to re - register with a password, but it's better than every single VI. Thank you!

    Use the option duplicate hiarchy and preserve...

    apply to all...

    at least as far my memories are good.

    Ben

  • Impossible to get top-level Ref Secondary VI VI

    I manipulate a control on the façade of a VI in a secondary school. The 'CvtPaneToPanelCoords' method returns a value in the coordinate system of the first level VI which has high school. I need to use the 'CvtPanelToScreenCoords' method on this value, but I can't get a reference to the top-level VI Panel. When I use the antiderivative of the call chain to find the first level VI, the last item in the list is

    My Class:Subpanel VI.ACBRProxyCaller.5AE00058
    

    Try to open a reference to this name, I get error 1004 (VI is not in memory).

    The ACBRProxyCaller is used by the node of the asynchronous call to reference, isn't it? My computer is running in some aspects of the implementation of the secondary? How can I get a reference to the VI that has secondary school in that my VI is inserted? And more precisely - because I'm actually nesting sub-panels in sub-panels - how to get a reference to the façade of the VI of above (the one that has the highest secondary level)?

    The primitive call chain only works for subVIs. A call to the CGRA isn't like the call of a Subvi, so it does not work.

    The basic answer to your question is to pass the reference in the VI yourself. If you have more complex logic, you have something like a driving force to keep the correct references.

  • Using the MS ODBC driver to connect to Oracle and MS SQL DB - get a time-out error

    I have the driver installed and configured on the Linux host where sits the Oracle DB.  I worked through the configuration and tested along the way.

    If I execute the following SQL statement I get a timeout error after only 15 minutes:

    SQL > select * from host_table@UCMDB806;

    Select * from host_table@UCMDB806

    *

    ERROR on line 1:

    ORA-28511: interruption of the RPC connection to heterogeneous remote agent to help

    SID = ORA-28511: lost RPC connection to heterogeneous remote agent to help

    SID = (Description = (Address = (Protocol = TCP)(Host=localhost) (port = 1521)) (CONNECT_DAT

    A = (SID = UCMDB806)))

    ORA-02063: preceding the line of UCMDB9

    Process ID: 4070

    Session ID: 392 serial number: 40935

    If I limit the SQL to give hosting me only that start with 'a', I get this:

    SQL > select * from host_table@UCMDB806 where (name) lower like 'a % ';

    ID

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

    NAME

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

    TenantID

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

    name of the vendor

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

    softwarename

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

    4616

    AHOST-B

    76436

    ID

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

    NAME

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

    TenantID

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

    name of the vendor

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

    softwarename

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

    SYMANTEC

    .

    .

    .

    It seems to be a time-out on this query.  My software is located 20 minutes for a query.  MS SQL server is set to unlimited for remote queries (we did it to help isolate the timeout).  So, I guess the wait time that is happening at the level of ODBC driver.  Someone has all understand how to solve this problem?

    Hello

    Your question is beyond the scope of this community.

    Please repost your question in the SQL Server TechNet Forums.

    https://social.technet.Microsoft.com/forums/SQLServer/en-us/home?category=SQLServer

    See you soon.

  • divide a string in order to get the level of separate list.

    Hello

    I want to divide a string in order to get the level of separate list to connect this with a category table.
    The size of my list is dynamic and for this reason, I am unable to find a way to do it!

    This is an example of what I need to do:
    Consider the following list:
    Category                Category_ID
    Age                     1
    Less than 3 months      1.1
    Less than 9 months      1.2
    Less than 1 year        1.3
    Risk                    2
    Danger                  2.1
    High                    2.1.1
    medium                  2.1.2
    low                     2.1.3
    If I have a row that has category_id "2.1.3" I want to present values as:
    "Risk.Danger.Low"
    If I have a row that has category_id "1.1" I want to present values as:
    "Age.Less than 3 months"
    No clue as to what I should look for to achieve this?
    This will serve to produce a report. This report contains a few lines of a thousand and the categories will be around 100.


    Thank you
    Ricardo

    Hello

    I think this is a job for sys_connect_by_path...

    with p as
    (   select 'Age'             descr  ,'1' cat from dual union all
       select 'Less than 3 months'      ,'1.1' cat from dual UNION ALL
       select 'Less than 9 months'      ,'1.2' cat from dual union all
       select 'Less than 1 year'        ,'1.3' cat from dual union all
       select 'Risk'                    ,'2' cat from dual union all
       select 'Danger'                  ,'2.1' cat from dual union all
       select 'High'                    ,'2.1.1' cat from dual union all
       select 'medium'                  ,'2.1.2' cat from dual union all
       select 'low'                     ,'2.1.3' cat from dual
    )
    SELECT
        cat,
        LTRIM(SYS_CONNECT_BY_PATH(descr,'.'),'.') route
    FROM
        (
            SELECT
                descr,
                cat,
                SUBSTR(cat,1,INSTR(cat,'.',-1)-1) parent
            FROM
                p
        )
    START WITH
        parent IS NULL
    CONNECT BY
        PRIOR cat = parent
    /
    SQL> with p as
      2  (   select 'Age'             descr  ,'1' cat from dual union all
      3     select 'Less than 3 months'      ,'1.1' cat from dual UNION ALL
      4     select 'Less than 9 months'      ,'1.2' cat from dual union all
      5     select 'Less than 1 year'        ,'1.3' cat from dual union all
      6     select 'Risk'                    ,'2' cat from dual union all
      7     select 'Danger'                  ,'2.1' cat from dual union all
      8     select 'High'                    ,'2.1.1' cat from dual union all
      9     select 'medium'                  ,'2.1.2' cat from dual union all
     10     select 'low'                     ,'2.1.3' cat from dual
     11  )
     12  SELECT
     13      cat,
     14      LTRIM(SYS_CONNECT_BY_PATH(descr,'.'),'.') route
     15  FROM
     16      (
     17          SELECT
     18              descr,
     19              cat,
     20              SUBSTR(cat,1,INSTR(cat,'.',-1)-1) parent
     21          FROM
     22              p
     23      )
     24  START WITH
     25      parent IS NULL
     26  CONNECT BY
     27      PRIOR cat = parent
     28  /
    
    CAT   ROUTE
    ----- ------------------------------
    1     Age
    1.1   Age.Less than 3 months
    1.2   Age.Less than 9 months
    1.3   Age.Less than 1 year
    2     Risk
    2.1   Risk.Danger
    2.1.1 Risk.Danger.High
    2.1.2 Risk.Danger.medium
    2.1.3 Risk.Danger.low
    

    HTH

    David

    Published by: Bravid on Sep 2, 2011 14:50

  • Count only the iterations of duplicates? [SOLVED]

    Using Oracle 9i 9.2.0.6.0.

    This could be something simple that I am on, there are plenty of ways to find and count duplicates but I'm looking for a way to count only the number of iterations of a duplicate, it is and then group them if possible.

    For example, suppose that you have
    store   customer   product    date
      1          John          A         2008/05/01
    
      1          John          A         2008/05/01
    
    
      1          John          B         2008/05/01
    
    
      2          Bob           C         2008/05/01
    
    
      2          Bob           C         2008/05/01
    
    
      3          Mary          D         2008/05/01
    
    
      3          Mary          D         2008/05/01
    
    
      3          Mary          D         2008/05/01
    
    
      3          Joe            F         2008/05/01
    So I don't want to go back to the following:
    Store    Duplicates
      1               1
      2               1
      3               2
    I want to only count how many duplicates beyond the first row for each store, where a duplicate has the same store, the customer and the product. Then
    1 John A 2 Bob C, had one double, and Mary has 2.

    I've tried so far to use analytical functions to subtract the first value of each partition before doing a count or make a number from each partition but niether seems to work by a group of store.

    Published by: a little rabbit on September 18, 2008 13:03

    You can find the number for each group and subtract one, as follows.

    SQL> create table t ( store int, customer varchar2(10), product varchar2(1), d_ate date );
    
    Table created.
    
    SQL>
    SQL> insert all
      2     into t values ( 1, 'John', 'A', date '2008-05-01' )
      3     into t values ( 1, 'John', 'A', date '2008-05-01' )
      4     into t values ( 1, 'John', 'B', date '2008-05-01' )
      5     into t values ( 2, 'Bob',  'C', date '2008-05-01' )
      6     into t values ( 2, 'Bob',  'C', date '2008-05-01' )
      7     into t values ( 3, 'Mary', 'D', date '2008-05-01' )
      8     into t values ( 3, 'Mary', 'D', date '2008-05-01' )
      9     into t values ( 3, 'Mary', 'D', date '2008-05-01' )
     10     into t values ( 3, 'Joe',  'F', date '2008-05-01' )
     11  select null
     12  from   dual;
    
    9 rows created.
    
    SQL>
    SQL> select distinct
      2         store
      3  ,      cnt - 1 as duplicates
      4  from  (
      5         select store
      6         ,      customer
      7         ,      product
      8         ,      d_ate
      9         ,      count(*) over (partition by store, customer, product) as cnt
     10         from   t
     11        )
     12  where  cnt - 1 > 0;
    
         STORE DUPLICATES
    ---------- ----------
             2          1
             1          1
             3          2
    

    Concerning

  • How is it when I try to open one of my favorte often visited Web sites I get a blank page with only the word 'false' in the upper left?

    How is it when I try to open one of my favorte often visited Web sites I get a blank page with only the word 'false' in the upper left?

    This just started happening the last two days.  I tried to add the url to my list to activate in Internet Options, also to accept the list for windows firewall. I rebooted and restored.

    It is annoying when I can't access Web sites on my PC.  There is no control parenting, nor is it a reason to be since I'm 57 years old, single, live alone and have no children, and not to mention that this isn't a single adult site. This is an auction site.  The same thing happens on a site of sports too.

    Hello

    Thank you for writing to Microsoft Communities.

    I understand how it could be frustrating when things do not work as expected. Please, I beg you, don't worry I'll try my best to resolve the issue.

    1. what operating system is installed on the computer?

    2. what version of Internet Explore do you use?

    3 have there been recent changes to the computer before the show?

    Please go ahead and follow the steps mentioned and later a update on the State of the question.

    Method 1: Start Internet explorer with the mode without modules and check.

    Click Start, all programs, accessories, System Tools, and click Internet Explorer (No Add-ons).

    If the problem does not persist in Internet Explorer (No Add-ons), then it is one of the Add-ons at the origin of this problem. Please follow the steps below to locate the problem the weak module:

    a. restart IE normally.

    b. click on tools.

    c. click on Manage Add-ons.

    d. disable add-ons by clicking on them one at a time to highlight and then click Disable.

    e. reactivate modules one by one and check with what add-on, you get this error message.

    f. turn off the add-on at the origin of the problem.

    For your reference: http://Windows.Microsoft.com/en-us/Windows7/Internet-Explorer-Add-ons-frequently-asked-questions

    (For Windows Vista)

    Method 2: How to optimize Internet Explorer:

    http://support.Microsoft.com/kb/936213/no

    Important: Reset Internet Explorer to its default configuration. This step will disable also any add-ons, plug-ins or toolbars that are installed. Although this solution is fast, it also means that, if you want to use one of these modules in the future, they must be reinstalled.

    Follow these recommended steps and after if you still experience the problem.

  • I get to level my windows in Windows 7 PC.  My old PC had CS6, Bridge, and Lightroom installed 5.7.  I want to remove all three of the old and install the new.  How do I do that?

    I get to level my windows in Windows 7 PC.  My old PC had CS6, Bridge, and Lightroom installed 5.7.  I want to remove all three of the old and install the new.  How do I do that?

    First of all make sure you disable / disconnect in order to save the number of activations.

    Click the help menu, and then select disable / disconnect .

    Then you can uninstall in Control Panel uninstall process as normal.

    Later, you can download and install CS 6 app link below:

    Download Creative Suite 6 applications

  • Questions about setting should level parent and units

    Hello

    We have a requirement for a sales manager for forecasting sales at level zero, for example
    by the customer. And the regional manager to adjust the number at the territory level (parent).
    Any ideas on the best way to do it.

    For example:

    Sales Manager input data to the Customer1, 2, 3, etc.
    Regional director can adjust to Total_Territory, and then return the data to the bottom. Basically, crush
    What was projected by the Sales Manager.

    Total_Territory 9
    | _Territory_A 4
    | __Customer1 1
    | __Customer2 1
    | __Customer3 2
    | _Territory_B 5
    | __Customer4 3
    | __Customer5 2

    Can we use target version to apply it?
    If we use the target version, can the user planned to Total_Territory even if there is a
    data on the client (level 0)?

    Any other ideas on how we can implement this requirement?

    The second challenge is what is planned is not the amount, but unit.
    If the regional manager you want to increase the target from 9 to 10.
    where should we allocate the additional unit of 1 to? And we cannot have
    Decimal into a unit.

    Thank you

    Lian

    Hello
    Out of curiosity, this could be an insurance company?
    I would recommend separating the target and down at the top of the versions and show them the two side-by-side to the users. Let your manager territory defined targets on the target version, but don't let it substitute the numbers upward. You can view the gaps in a third column to alert the Director of sales and Territory Manager. Responsible for sales can be held accountable for the achievement of the objectives. In my view, precisely assign targets to individual customers requires a judgment call and sales only for this Manager. So, I recommend you to perform the calculation of the allowance to the version target.
    Regarding decimals, if you create a fictitious client under each territory and mark them with an attribute or UDA, you can place the rest of the distribution of your integer to this member. It helps the sales managers to understand that there is an additional objective for the territory which is not shared among customers yet. If the structure that I would recommend would look like this:
    Territory 1
    -Territory 1 client buffer<--Dummy>
    -Client 1
    -Client 2
    -etc.

    See you soon,.
    Alp

  • How can I count only text fields that have been used?

    Hello

    I use Livecycle Designer to a dynamic form.  I have a section of the form that contains the field for the user to enter the goals, and then note the purpose.  I want to count only the text fields with entries and have the total number of rates, divided by the number of entries in text field.

    Line 1, column 1 - goal is to collect 5 apples.   Line 1, column 2 - the given rate is 5

    Row 2, column 1 - goal is to collect 5 pears.  Line 1, column 2 - the given rate is 5

    Two goals for a total power of 10-10 divided by 2 = 5

    Is it possible to count only the fields that are populated?

    Also, is it possible to create an error message if the user scored 5 goals but rated only 4 of them?

    Please send me the form to

    [email protected]. I'll get it repaired for you and send it back and then you'll have the code in the form of sample for later reference.

  • How to get to level 2 in apple support

    How to get to level 2 in apple support

    < re-titled by host >

    You mean on this forum?

    Answer the questions and eventually you're going to collect enough points to become level 2.

    https://discussions.Apple.com/docs/doc-9251

    He explains

  • VI marking as first level during construction

    All by building a Bachelor's degree in LAW, is it possible to specify screws in the upper level. I wasn't able to see an option for this in the construction specifications. I'm using LabVIEW 8.6.

    Thank you!

    In the file Source settings page, you can mark files as the first level.

    Don't forget that you can include files from LabVIEW within a Bachelor of law

    Tone

  • After I loaded Turbo Tax 2011, after that I connect to my PC, I get a blank screen with only the cursor showing. I am on Windows Vista.

    After I loaded Turbo Tax 2011, after that I connect to my PC, I get a blank screen with only the cursor showing. I picked up at an earlier date and reloaded the software TT 3 times with the same result. I tried of caraa start windows Explorer by using the Task Manager, but it does not work.

    Hi AndyCantore,

    Follow these steps:

    Step 1: Start the computer in safe mode and check if the problem persists.

    Start your computer in safe mode

    http://Windows.Microsoft.com/en-us/Windows-Vista/start-your-computer-in-safe-mode

    Step 2: If the problem does not persist in safe mode, perform a clean boot to see if there is a software conflict as the clean boot helps eliminate software conflicts.

    Note: After completing the steps in the clean boot troubleshooting, follow the link step 7 to return the computer to a Normal startupmode.

  • Get rid of Parental control on my guest account

    Why can't get rid of parental control on my guest account!  It is said you can not set up parental controls for the guest account and yet when I try to connect it throws up of all these parental controls!  I watched & tried and tried again to fix it.  Very frustrated here, especially with guests coming for the holidays! I just set up a password for the guest account...

    Hello

    See this and the 'related links' here and I hope that you find the answer. You may need to remove
    all parental controls and try again. You have Ultimate or business where group policies would come
    in game (GPEdit)?

    How to install and use Parental controls in Vista
    http://www.Vistax64.com/tutorials/95139-parental-controls-Setup-use.html

    and these:

    Setting up Windows Vista's Parental control
    http://www.bleepingcomputer.com/tutorials/tutorial139.html

    Set up Parental controls
    http://Windows.Microsoft.com/en-us/Windows-Vista/set-up-parental-controls

    I hope this helps.
    Rob - bicycle - Mark Twain said it is good.

  • Any code can get battery level and level of radio signal?

    Any code can get battery level or the level of radio signal?

    I tried to get the code of code of the radio signal power level and battery level, but not able to find related information in Google and NDK reference.

    The two levels are exist developing Smartphone BlackBerry in the Java API.

    If anyone knows how to get the level of signal radio such as wireless or battery and so on, pls help me how to get it.

    Thank you for your attention.

    Hello

    The best level and Radio API level are not supported from now and they are in the road map to be supported in the future.

    Thank you

    Naveen M

Maybe you are looking for