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.

Similar Messages

  • 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

  • How to write Select statement for this codition

    I need to check whether SGTXT contains BELNR value.
    SGTXT is a text field and It should be matched with BELNR
    How to write select statement for this.
    Select AUGBL AUGDT into t_BSAD
    from BSAD
    where SGTXT should have the given BELNR Value.
    Plz note : Here I cannot give as SGTXT = BELNR as coz BELNR have only 10 digits.

    Hi,
    data temp(12).
    concatenate '%' belnr '%' into temp.
    Select AUGBL AUGDT into t_BSAD
    from BSAD
    where SGTXT like temp.
    If belnr is having multiple values,just create a internal table as follows.
    types : begin of ty,
            belnr....
            temp(12),
            end of ty.
    data itab_ type standard table of ty.
    data wa type ty.
    loop at itab into wa.
    concatenate '%' wa-belnr '%' into wa-temp.
    modify itab from wa index sy-tabix transporting temp.
    endloop.
    Change your select statement accordingly.
    Kindly reward poits if it helps.

  • How to write a PCR for this ?

    Hi SAP-HR Experts .
    Dear friends , My Company Requires a specific requiremnt that at the date of any Employee's
    B'day his one day salary should get doubled and he is entitled to get one leave on his B'day .
    I do not know how to write a PCR for this ?
    May some Body tell me how to meet this requirement Please .
    tell me please step by step how to go through ...
    It will be great help for me .
    Best regards : rajneeesh

    I think you can make it with something like this:
    Write a PCR in schema, you can call the rule with "actio";
    000860 ACTIO 9BIR AR               Birthday
    Rule 9BIR
    9BIR Rule for Birthday
            NUM=FG C   Set                   " F (fixed indicator for deadline calculation); G (Birth date from infotype 0002);C (complete months)
            NUM/12     División              " Number of completed months divided by  12
            NUMV0O2L   Off.Lng en arg.var.   " the last two places of the number are entered in the variable argument.
                                " if the rest is not 00, there is nothing to do
              00                             " if the rest is 00
                ZERO= N    AmtNumRteZeit = 0 "
                AMT=  1002 Set               " wagetype of  salary
                AMT/TKDIVI División          " divides the amount by  Partial Period Parameter Whole Month
                ADDWTI1002 Input table       " accumulates into 1002
    Example: an employee with birthday 01.01.1977 in IT0002
    Payrroll in january 08
    wagetype 1002 before rule 9BIR:
    3 1002 Salario Bas01                           30,33  30,00              909,90
    Rule 9BIR
    NUM=FG C   Set; NUM= 372
    NUM/12        ; 372/12= 31 rest=00
    AMT=1002      ; AMT= 909,90
    AMT/TKDIVI    ; 909,90/31= 29,35
    ADDWTI1002    ; 909,90 + 29,35= 939,25
    wagetype 1002 before rule 9BIR:
    3 1002 Salario Bas01                           30,33  30,00              939,25
    Hope this helps. Manuel

  • How  to write  a  query  for this output

    I have a string ' if i know good acting , I am a hero '
    now if 'hero' is present in the string it will return ' i am hero' else
    'you are hero'
    How to write a sql query to return the same .

    SQL> select (case
    2 when '&a' like '%hero%' then 'I am hero'
    3 ELSE 'u r hero'
    4 end) output from dual;
    Enter value for a: if i know good acting , I am a hero
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'if i know good acting , I am a hero ' like '%hero%' then 'I am hero'
    OUTPUT
    I am hero
    SQL> /
    Enter value for a: jkhkh
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'jkhkh' like '%hero%' then 'I am hero'
    OUTPUT
    u r hero
    Hope this helps.

  • How  to write select query for this

    Hi,
    I had a html form and in the for i had drop down box and it needs to select multiple values from the drop down box. When i select multiple values then i have to write the SQL select statement  query .
    When i try to write the select statement and trying to run i am getting error.
    select * from Table
    where emo_no = '1,2,3'
    this is how i write query please suggest me how  to write query for selecting multiple values from the drop down box.
    Thanks

    select * from Table
    where emo_no in ( 1,2,3)
    for integer values
    select * from Table
    where emo_no in ('1','2','3')
    for characters
    If we talk about large scale applications that may have millions of records, I would suggest this.
    declare @t table (v int)
    insert into t (v) values (1)
    insert into t (v) valves (2)
    insert into t (v) values (3)
    select *
    from table
         inner join @t t on table.emo_no = t.v
    Using "in" for a where clause is not so bad for filtering on a few values, but if you are filtering a lot of rows and a lot of values (emo_no) the performance degrades quickly for some reasons beyond the scope of this.
    This is just one solution, I'll through this out as well, instead of an in memory (@t) table, doing a disk based temp table (#t) and creating an index on the column "v".
    create table #t (v int)
    insert into #t (v) values (1)
    insert into #t (v) valves (2)
    insert into #t (v) values (3)
    create index ix_t on #t (v)
    select *
    from table
         inner join #t t on table.emo_no = t.v
    drop table #t
    Pardon any syntax errors and careful using a drop statement.
    Sometimes in memory tables work better than disk temp tables, it takes some testing and trial and error depending on your datasets to determine the best solution.
    Probably too much info  ;-)
    Byron Mann
    [email protected]
    [email protected]
    Software Architect
    hosting.com | hostmysite.com
    http://www.hostmysite.com/?utm_source=bb

  • How to write a query for this data??

    In this table i have column dob which is DATE type,for example 12-jan-89 I want output like this
       Year              Day
    12-jan-89         Thusrs_day
    12-jan-90          Friday
    upto
    12-jan-14        sunday

    krishnagopi wrote:
    No not like that ,I want up to 2014 year
    Ok, so lets say you have table like this
    SQL> create table my_table(dob date);
    Table created.
    SQL> insert into my_table (dob) values( to_date('12-jan-1989', 'dd-mon-yyyy'));
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from my_table;
    DOB
    12-JAN-89
    You can write a query like this
    select dob + (level -1) dob
          , to_char(dob + (level -1), 'fmDay') day_
       from my_table
    connect
         by level <= (dob + interval '25' year) - dob + 1;

  • How to write a class for this?

    how do i write a different class for this? how do i implement the "a.add(b)"? it code is to test basic arithmetic operations.
              System.out.print ("Arithmetic: enter two integer numbers: ");
              Integer a = new Integer (Integer.parseInt(kbd.readLine()));
              Integer b = new Integer (Integer.parseInt(kbd.readLine()));
              System.out.println (a + "+" + b + "-" + b + "*" + a + "/" + a + "%" + b + " is: "                                    + a.add(b).sub(b).mul(a).div(a).rem(b));                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    public class arthOperation{
         add()
              sub()
         sub(){
              mul()
         mul(){
              div()
         div(){
              rem()
         rem(){
    is it write?

  • How to write a DTD for this scenario?

    hi,
    consider the following xml
    <set after = "A">
    <item name="A" ></item>
    <item name="B" ></item>
    </set>
    The DTD for the "item" element is
    <!ATTLIST item name (A | B| C| D| E ) #REQUIRED >
    The attribute "after" of "set" can hold a single valid name like
    <set after = "A">
    or
    a collection of valid names seperated by coma like <set after = "A,B,C">
    how to write DTD for the "after" attibute such that it will contain a single valid name or collection of names?
    Regards,
    Ajay.

    I could be wrong, but I'm pretty sure that DTD doesn't support that. You're probably better off declaring the name attribute to be of type PCDATA and tokenizing the value manually in code.

  • 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
    )

  • 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 a query for this situation

    Hi ,
    Can any one help me to write a query.I have a table with three columns like char_id_1,char_id_2,char_id_3,these data have to insert into some other table but in the target table the data should be comma seperated like (10,8,2),here blank space indicates null.In source table the columns are numbers,but in target table it is varchar2.
    source table:
    CHAR_ID_1 CHAR_ID_2 CHAR_ID_3
    10 8 2
    7 1 5
    4 11
    6 1
    2 8
    6 12 7
    Target table:
    CHAR_IDS
    10,8,2
    7,1,5
    4,11
    6,1
    2,8
    6,12,7

    I started doing it to_char way, and thought of some different version, and ended up with an ugly solution which works only if you have three columns. Thought of not posting, but posting it anyway:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> with t as(
      2      select 10 c1,8 c2,2 c3 from dual union all
      3      select 7,1,5 from dual union all
      4      select 4,null,11 from dual union all
      5      select null,6,1 from dual union all
      6      select 2,8,null from dual union all
      7      select null,8,null from dual union all
      8      select null,null,10 from dual union all
      9      select 2,null,null from dual union all
    10      select null,null,null from dual union all
    11      select 6,12,7 from dual )
    12  --
    13  select nvl2(c1,
    14              c1 || nvl2(c2,',' || c2 || nvl2(c3,',' || c3,null),nvl2(c3,',' || c3,null)),
    15              nvl2(c2, c2 || nvl2(c3,','|| c3,null),nvl2(c3,c3,null))) col_concat
    16  from t;
    COL_CONCAT
    10,8,2
    7,1,5
    4,11
    6,1
    2,8
    8
    10
    2
    6,12,7
    10 rows selected.
    SQL>

  • How to write a query for this

    I have 2 tables
    emp_master (emp_id, emp_name)
    dept_master (dept_id, dept_name, emp_id (references emp_id in emp_master)Now there are 30 departments and each department can have maximum 5 employees.
    Now I want a query that would list a department and all its employees in one line and if there are less than 5 employees it would show null for the rest of columns.
    Dept_id emp_1 emp_2 emp_3 emp_4 emp_5
    1 1 2 -- -- --
    2 3 4 5 6 7
    3 8 -- -- -- --
    Please help me out
    Thanks...

    One solution may be
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL>
    SQL> SELECT e.department_id, e.employee_id
      2    FROM employees e
      3   WHERE e.department_id IN (10, 20, 40, 60, 90)
      4  /
    DEPARTMENT_ID EMPLOYEE_ID
               90         100
               90         101
               90         102
               60         103
               60         104
               60         105
               60         106
               60         107
               10         200
               20         201
               20         202
               40         203
    12 rows selected
    SQL>
    SQL> SELECT ee.department_id, ee.emp_1, ee.emp_2, ee.emp_3, ee.emp_4, ee.emp_5
      2    FROM (SELECT MAX(CASE
      3                       WHEN MOD(r, 5) = 1 THEN
      4                        e.employee_id
      5                       ELSE
      6                        NULL
      7                     END) emp_1,
      8                 MAX(CASE
      9                       WHEN MOD(r, 5) = 2 THEN
    10                        e.employee_id
    11                       ELSE
    12                        NULL
    13                     END) emp_2,
    14                 MAX(CASE
    15                       WHEN MOD(r, 5) = 3 THEN
    16                        e.employee_id
    17                       ELSE
    18                        NULL
    19                     END) emp_3,
    20                 MAX(CASE
    21                       WHEN MOD(r, 5) = 4 THEN
    22                        e.employee_id
    23                       ELSE
    24                        NULL
    25                     END) emp_4,
    26                 MAX(CASE
    27                       WHEN MOD(r, 5) = 0 THEN
    28                        e.employee_id
    29                       ELSE
    30                        NULL
    31                     END) emp_5,
    32                 e.department_id
    33            FROM (SELECT row_number() over(PARTITION BY department_id ORDER BY employee_id) r,
    34                         department_id,
    35                         employee_id
    36                    FROM employees
    37                   WHERE department_id IN (10, 20, 40, 60, 90)) e
    38           GROUP BY e.department_id) ee
    39  /
    DEPARTMENT_ID      EMP_1      EMP_2      EMP_3      EMP_4      EMP_5
               10        200                                 
               20        201        202                      
               40        203                                 
               60        103        104        105        106        107
               90        100        101        102           
    SQL> Regards...

  • 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 write Error message for select options?

    Hi
    i have this select option statement
    SELECT-OPTIONS: s_fevor FOR afko-fevor.
    how to write error message for this?
    Regards
    Smitha

    Error messages are displayed for Select-options mostly on two conditions:
    1) You needs to check wether a value is entered or not its done by:
    a)
    Select-options:SELECT-OPTIONS: s_fevor FOR afko-fevor Obligatory.
       In this case error message is automatically throwed by system.
    b) You can do this in Selection Screen events.
    Ex:
    AT SELECTION-SCREEN./AT SELECTION-SCREEN ON S_FEVOR.
    IF S_FEVOR-LOW IS INITIAL.
    MESSAGE 'XXXXX' TYPE 'E'.
    ENDIF.
    2) You need to Validate the entered value:
    You can do this in Selection Screen events.
    Ex:
    AT SELECTION-SCREEN./AT SELECTION-SCREEN ON S_FEVOR.
    SELECT FEVOR
                 FROM AFKO
                 INTO AFKO-FEVOR
                 UP TO 1 ROWS
    ENDSELECT.        
    IF SY-SUBRC NE 0.
    MESSAGE 'XXXXX' TYPE 'E'.
    ENDIF.
    Regards,
    Gurpreet

Maybe you are looking for