How to correct the sql for this

Here is my requirement
How to find the master apps for this.
If there is rollup info for a app then it is parent
Rollup info is present in table B with flag R
Table A
AppNo Name
1 abc
2 xyz
3 pqr
4 mno
5 stu
6 ccc
7 ddd
Table B
srce dpnt flag
1 1 R
2 6 R
2 7 R
3 4 R
So now the parent apps are 1,2,3 since they have children (1,6,7,4)
Now i want 5 to be included in the parent list as it is an independent app
Appno name
1 abc
2 xyz
3 pqr
5 stu
my query is not including appno
appno name
5 stu
select * from TableA a
where a.appno in (
select distinct SRCE from TableB where b.SRCE=a.appno
and b.flag='R' )

one solution:
select srce from table_b
union
select appno from table_a
minus
select dpnt from table_b
)

Similar Messages

  • How to write  complex sql for this

    Hi ALL,
    I have a requirement like this
    I have 5 tables which i have to join to get the result
    but there no join column to 2 other table.
    I want to get all the applications using cobal,running on UNIX.
    How to write the query for this
    1.APP
    APP_i DESC
    1 Accounts
    2 Payments
    3 order transfer
    4 Order processing
    2.Techgy
    techid techdesc
    1 cobal
    2 Java
    3.APP_Techgy
    APP_I Techid
    1 1
    2 1
    3 1
    4 2
    4.Pltfrm
    pltfmid pltfrmdesc
    1 Windows NT
    2 UNIX
    5.APP_Pltfrm
    APP_I pltfrmid
    1 1
    2 1
    3 2
    4 2
    ouput must be
    APP_i Desc techDESC pltfrmdesc
    3 ordertranfer Cobal UNIX
    Thanks in advance

    This ('descr' in place of 'desc')?
    SQL> select a.app_i, a.descr, t.techdesc, p.pltfrmdesc
    from app_techgy atc,
       app a,
       techgy t,
       app_pltfrm ap,
       pltfrm p
    where atc.techid = t.techid
    and atc.app_i = a.app_i
    and atc.app_i = ap.app_i
    and ap.pltfrmid = p.pltfmid
    order by a.app_i
         APP_I DESCR                TECHDESC             PLTFRMDESC         
             1 accounts             cobal                windows nt         
             2 payments             cobal                windows nt         
             3 order transfer       cobal                unix               
             4 order processing     java                 unix               
    4 rows selected.

  • HT4623 i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS

    i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS

    look at this thread
    https://discussions.apple.com/message/22837309#22837309

  • How to reduce the cost for this select script

    Hi,
    "select id from order where cmd like 'Error ID %'"
    This s my script. And the order table has morethan *5lakhs* records, when i select id for the above condition, my sql script cost is - *2200*,and cpu_cost is -- *235660697* i got this above information thro' plan_table, could anyone plz give suggestion to reduce the cost. (fyi -- cmd field has index with not null constraint).
    Thanks.

    user13294228 wrote:
    "select id from order where cmd like 'Error ID %'"
    This s my script. And the order table has morethan *5lakhs* records, when i select id for the above condition, my sql script cost is - *2200*,and cpu_cost is -- *235660697* i got this above information thro' plan_table, could anyone plz give suggestion to reduce the cost. (fyi -- cmd field has index with not null constraint).What does these cost numbers mean? Do you know what it means and what measurement unit is used for these costs? Will a cost of 2000 be fine? 1500? What specific number will make you sit back and think that the cost is now acceptable?
    Or instead, do you not think it is more important to rather look at what the query does and why.. and then determine if there are methods to do that better and faster?
    So let's look at what the query does. It uses a a LIKE predicate. This means that if an index is available, it cannot be used to find a specific indexed value... as the query is not sure what the value is. All that the query knows is what the first couple of characters are for the value.
    So how would an index be used? Have you looked at the execution plan? Do you understand why the CBO made the decision it did?
    Now - how do you expect the CBO to find the relevant rows any faster? The index benefits the query how? As the CBO cannot put the index to any better use than what it is already doing, what other options are there? Can alternative indexing or data structures be considered? Can parallel processing be used?
    These questions are intended to make you analyse the problem - and understand the problem. That is always the 1st step.. solving the problem only comes after this 1st step.

  • How to meet the requirment for this infospoke

    Hi Experts
      Please update me on how to proceed to meet this requirment.
      I am building a Infospoke on a Cube to export data to Application Server.
      In my Cube i had a CHAR Department.
    Department got a time Dependent Navigational Attribute 'MANAGER'
    My requirment is...
       In my infospoke I had a field included Manager....
    This should be populated during run time by reading Time Dependent Master Data Table based on Employee and Current date..it should get Manager
    Please update wether Routine is the only way or any alternatives for this requirment...that i can set in Transformations
    Thanks

    Found it...
    http://help.sap.com/SAPHELP_ERP2004/helpdata/EN/49/7e960481916448b20134d471d36a6b/content.htm
    Regards
    Juan

  • How to write the SQL for the following

    ID     PRODUCT     LEAD_FLAG     SALES_VOLUME
    1     A     Y     100
    1     B     N     200
    1     C     N     300
    1     D     N     400
    2     A     N     10
    2     B     Y     20
    2     C     N     30
    2     D     N     40
    I need to calculate the incentive for each ID. The rule is for an ID:
    if the the lead flag for a product is N, then check the sales_volume of the product whose lead_flag is Y (product A in case of ID 1, product B in case of ID 2). if the sales_volume of the product with lead_flag = Y is greater than a NUMBER (this NUMBER varies from product to product. for product A it is 20, for product B it is 25, C it is 30 and D it is 40) then incentive = (sales_volume of the product with lead flag N) * 100.

    Hello, I presume the NUMBER you refer to will be held in a table column somewhere? I'm calling it threshold_num in the test data below (and rec_id instead of ID):
    WITH test_data AS (
    SELECT 1 REC_ID, 'A' PRODUCT, 'Y' LEAD_FLAG,  100 SALES_VOLUME FROM DUAL UNION ALL
    SELECT 1, 'B','N', 200 FROM DUAL UNION ALL
    SELECT 1, 'C','N', 300 FROM DUAL UNION ALL
    SELECT 1, 'D','N', 400 FROM DUAL UNION ALL
    SELECT 2, 'A','N', 10 FROM DUAL UNION ALL
    SELECT 2, 'B','Y', 20 FROM DUAL UNION ALL
    SELECT 2, 'C','N', 30 FROM DUAL UNION ALL
    SELECT 2, 'D','N', 40 FROM DUAL),
    test_ref_data AS (
    SELECT 'A' PRODUCT, 20 threshold_num FROM DUAL UNION ALL
    SELECT 'B', 25 FROM DUAL UNION ALL
    SELECT 'C', 30 FROM DUAL UNION ALL
    SELECT 'D', 40 FROM DUAL)
    -- end test data
    SELECT td1.REC_ID, td1.PRODUCT, CASE WHEN td2.PRODUCT IS NOT NULL THEN td1.sales_volume * 100 ELSE 0 END incentive
      FROM test_data td1
       LEFT JOIN (
        SELECT td2.PRODUCT, SUM(sales_volume) sales_volume
         FROM test_data td2
         JOIN test_ref_data trd
            ON (td2.PRODUCT = trd.PRODUCT)
       WHERE td2.lead_flag = 'Y'
        GROUP BY td2.PRODUCT, trd.threshold_num HAVING SUM(td2.sales_volume) > trd.threshold_num) td2
        ON (td1.PRODUCT = td2.PRODUCT)
    WHERE td1.lead_flag = 'N';
        REC_ID PROD  INCENTIVE
             2 A       1000
             2 D          0
             1 D          0
             1 B          0
             2 C          0
             1 C          0
    6 rows selected.And two tips: it's always helps to put {noformat}{noformat} before and after your code for readability, and also to provide expected sample output.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to construct a SQL for this logic.

    Hi,
    I have a requirement like, i need to derive a column with a calculation.
    Here is the psedocode,
    count of occurance (deptno=10)/count (deptno=10)
    Desired result:
    If the deptno =10 occurs 3 times in the table then at the fist time the calcuation should be,
    1/3, second time 2/3, third time 3/3 and so on.
    How can i construct this in a sql query. Please help.
    Any help will be appreciated with points.
    Thanks.

    WITH DATA AS
    (SELECT DEPTNO,
      ROW_NUMBER() OVER(PARTITION BY DEPTNO ORDER BY DEPTNO) RN,
      COUNT(DEPTNO) OVER(PARTITION BY DEPTNO ORDER BY DEPTNO) CNTDEPTNO
    FROM SCOTT.EMP)
    SELECT DEPTNO, RN, CNTDEPTNO, TO_CHAR(RN)||'/'||TO_CHAR(CNTDEPTNO) AS CNT
    , RN/CNTDEPTNO AS calcl
    FROM DATAyou want this?
    Edited by: Mahir M. Quluzade on Mar 10, 2011 10:59 AM

  • How to write Dynamic SQL for this SQL ?

    EXECUTE IMMEDIATE 'select COUNT(*) from dba_Tab_privs@' ||db_link|| ' WHERE Grantee <> 'DELETE_CATALOG_ROLE'
    AND Table_Name = 'LINK$'
    AND Grantee NOT IN (SELECT Grantee
    FROM dba_Role_privs
    WHERE Granted_Role = 'DBA')' into i using x;

    Hi bapalu,
    I take that x is the name of your db_link?
    If so,
    DECLARE
       i      NUMBER;
       x      dba_db_links.db_link%TYPE;
       stmt   VARCHAR2(255);
    BEGIN
       x := 'some_link';
       stmt :=
          'SELECT count(*)
             FROM dba_tab_privs@:db_link
            WHERE grantee <> ''DELETE_CATALOG_ROLE''
              AND table_name = ''LINK$''
              AND grantee NOT IN(SELECT grantee
                                   FROM dba_role_privs
                                  WHERE granted_role = ''DBA'')';
       EXECUTE IMMEDIATE REPLACE(stmt, ':db_link', x)
                    INTO i;
       dbms_output.put_line('The count: ' || i);
    END;Also, I think this is maybe not what you want:
    AND table_name = ''LINK$''Regards
    Peter

  • Does anyone know how to correct the download for itunes error message 7 windows 193?

    I'm getting error message 7 (windows 193) when I download new itunes update.

    Try  Troubleshooting issues with iTunes for Windows updates - MSVCR80

  • Need the Logic for this Prg issue Pls

    Hi Friends,
    i have an urgent requirement..
    i am develop the report that is :
    Based on Selction Critirea kunnr(knvv-kunnr)
    i want Delete the
             Internet mail (SMTP) address FROM ADR6-MTP_ADDR
    AND Teletex number FROM ADR4-TTX_NUMBER..
    USING TABLES ARE KNVV , ADR6 AND ADR4.
    please how to Write the LOGIC For this Program .
    help me.. it is an urgent.. anyone.
    regards,

    Hi Alchermi,
    thanks for your reply soon.
    based on selction kunnr .. i want deete the ADR4-TTX_NUMBER..and ADR6-SMTP_ADDR From these 2 tables
    for these 2 fields..
    kunnr from knvv, selection field..
    below fields want be DELETED..
    ttx-number from adr4,
    smtp_addr from adr6.
    it is an urgent. help me .
    regards,

  • How to create the request for change of selection text into other language.

    Hi,
    In my object requirement is that when login through Japanese language,  then on selection screen selection text should appear in Japanese language. For that I have maintained the text in Japanese language the program where we define the selection text there from translation I have maintained the text in Japanese but while maintain the text it didn't ask me for REQUEST, because of that I am not able to transport the changes to next system, so I want know how to create the request for this case.
    Thanks

    Hello Chetan,
    You could goto the selection screen texts by goto-> selection texts,
    Then you could again goto -> Translation
    or
    Other-> Translation(Not sure )
    Then double click on the Program you should be able to see the Texts that need translation, now change something save and come back and try to activate, now it should propose for a new Transport Request.
    Either create a new transaport request or give one that you have given for the program.
    Hope the issue is resolved.

  • How the files are decreasing from RBS storage after some time i delete docs from document library, where shld I check the settings for this?

    HI
    I created a web application and configured  rbs storage ,
    I uploaded documents (for ex: 18 number)
     after uploaded  documents ,  and observed the RBS storage folder, number of files are increasing (39 number) , its working fine
    and also  I run the querys to check the rows increasing or not , (when I upload new doc rows are increased its fine also)
    select count(*) from alldocs
    Select count(*) from AllDocstreams
    but when I delete some docs from document library ,
    1)the doc itself deleted from document library
    2)when I check the rbs storage  there is no number of files are decreased(its still 39 files ), its same as  before doc deleted from doc library
    after some time I found the number of files are decreasing from RBS storage folder in sql server,
    here I want to know the how the files are decreasing from RBS storage  after some time, where  shld I check the settings for this? and how I control on it
    here how I know the settings for cleaning up orphan BLBOS how  these deleted BLOB
    adil

    1. WHen you delete the file from Sharepoint, it is still present in Recycle bin. This is a default setting in sharepoint for 30 days. Once files are deleted fro Recycle bin, it can also be delete from RBS
    2. There is a RBS cleanup job which deletes files from RBS. for more info check 
    http://mehuljamod.blogspot.in/2012/09/remote-blob-storage-maintainer-rbs.html

  • How to correct the birth date in Apple account? How to change the numerals to English for UAE location?

    I purchased iPhone 5S and opened new Apple account with preffered language English and location UAE. I was directed to enter my birth date with only Arabic language option. There was no way to change the language or skip the step. I had to enter an arbitrary birth date to go to the next step. How to correct the birth date now and change the numerals to English?

    Solution!!
    I was finally able to get the installer build to work, even though it takes about ten minutes!!  The network and CPU activity is minimal, so I don't know what LV is waiting on during all this time?
    For this installation it appears to be related to the directory structure created by the Volume License Manager 2.1 software.  There are two sets of users at my company, LabVIEW Professional and Developer Suite, which have different license numbers and installers.  The errors were related to source files located in the Products folder of the network distribution.  My installation expected the Products folder to be in a different location that it was actually placed by the VLM software.  I copied the entire Products folder from _SourceFiles up to the LabVIEW 8.5.1 folder and now it works, although very slowly.
    LabVIEW 8.5.1
    -->_SourceFiles
        -->Bin
        -->Device Drivers
        -->Licenses
        -->Products   (original location)
        -->Signal Express
    -->Dev Suite
    -->LV Pro
    -->Products    (manual copy)
    I hope this information may be of use to NI or other users.
    Message Edited by jrjones on 08-12-2008 03:21 PM
    Message Edited by jrjones on 08-12-2008 03:23 PM

  • Why do I get and how do I correct the message _ This video is only available in the US - when I am in the US - I am trying to view Downton Abbey on my Ipad using the PBS app.?

    why do I get and how do I correct the message _ This video is only available in the US - when I am in the US - I am trying to view Downton Abbey on my Ipad using the PBS ipad app.? Thanks for your help

    Privacy is an Option in the Settings App, its not in Safari as that applies only to Safaris browsing.  Its called Privacy in  IOS 6  In previous versions the same thing can be found under Location Services.

  • How do you set the time for this forum??? Not in nerd pleas

    how do you set the time for this forum?

    There were problems with the correct time display for postings, and based on another recent post this doesn't seem to have been fixed. My advice... don't worry about it.

Maybe you are looking for

  • Is email address significant as an identifier

    I downloaded and set-up Digital Editions under one email address and bought a ebook, that I cannot seem to access, under a different email address. Do the email addresses need to be the same? AND, if so - How do I change the email in the authorizatio

  • My mac is from around 2005. is there any possible way me to put os x mountain lion onto my mac

    my mac is from around 2005. is there any possible way me to put os x mountain lion onto my mac

  • Timer in separate Thread.

    Hi. In my application i have a timer use to tick after every second and update a lable on UI. problem i was facing was that when time is enable none of the touch event was working. I googled it and found that i have to call timer function from anothe

  • Error in Cache purge using nqCmd.exe

    Hi, While excuting the nqCmd.exe giving error as shown below. !http://img685.imageshack.us/img685/5373/capture2pm.png! PurgeAllCache.sql is shown below. !http://img685.imageshack.us/img685/1791/capture4h.png! How to eliminate the error and purge the

  • Use Time machine to back up data from one external drive to another

    I keep my entire archive of digital photogarphy (700 gb) in a folder on an external drive. I want to duplicate that folder on another external drive and use Time Machine to automatically synch and add new photos to this back up folder on another driv