How should i write a query for this?

Hi i give the follwing query to implement the result,
IT will gives you the result of one country machines information like Total machines failed machines and success machines of their count
Countyr Name  CountryCode  Total Machines Failed Machines and Succes machines and their perentage
  IT  ITALY
1000 20
980    98% 
like these i want to display the 16 countyr machines information all country information in one palce  like table format
i will give you the query to the below here it is the combination of powershell code also used here with sql code.
Code as Country 
Name as Country
And below i mentioned OU in bold every where i will put the country code according to the country
like OU=FR
Select
        'FR' as 'Code',
        'FRANCE' as 'Name',
        (select COUNT(*) from ADComputersInfo where
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    (select COUNT(*) from ADComputersInfo where
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    (select COUNT(*) from ADComputersInfo where
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    (select COUNT(*) from ADComputersInfo where
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    (select count(distinct(cn)) from ADComputersInfo where
    (ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com')
    and cn in (select name0 from v_R_System)
    (select count(distinct(cn)) from ADComputersInfo where
    (ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com')
    and cn not in (select name0 from v_R_System)
    select count(distinct(cn)) from ADComputersInfo where
    (ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com')
    and cn in (select name0 from v_R_System where Client0 =1 and Obsolete0 =0)
    select count(distinct(cn)) from ADComputersInfo where
    (ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
    or
    ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com')
    and cn not in (select name0 from v_R_System where Client0 =1 and Obsolete0 =0)
So here i pass the County code and country name and OU=FR(assigned country code ) 
so hw we can all these 3 values in all the query can give me the r8 query for this . And i will get the all 16 country information 
Ineed exact query hw we can implement..........................................
I might be excepting lot from our side guys...
Thanks ! 
Advanced

Hi 
Can you simple post sample data + desired result? Always state what version you are using..
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • How should i write a pcr for this requirement?

    Dear Friends,
           Can any tell me whether we can write a pcr in such a way that if the person resigns the company on any day after 15th his full absence quota(for that month) should be accrued.
          if yes can you tell me  
          what are the key decision parameters i have to use in writing the pcr.
            waiting for you kind reply.
    Regards,
    Sai Prasad.

    Hai Prasad,
    I can give you the logic, cannot write exact rules.
    While genegarting absence quota
    - Check for termination action using OUTWPMASSN
        - If yes
              Check for Action year current year. (HRS=YSAY, HRS?CURYR)
                  - If its equal to 0
                      Check for current month (HRS=YSAO, HRS?CURMO)
                           - if its equal to 0
                                  check for current day (HRS=YSAA, HRS?CURDY
                                        - if its >=15
                                             generate quota
                           - Exit
    (Note: for this logic you have to generate monthly quota)
    With regards
    Shyam V

  • How can I write a query for this table?

    Dear friends
    I have a table with the following structur and data
    ID Name Value
    1 book 100
    2 book 200
    3 car 25
    4 car 35
    5 book 300
    now I would like write a query with following out put
    Name value
    book 100 , 200 , 300
    car 25 , 35
    (with , Separator) (my oracle version is 10g)
    thanks

    Try this,
    SQL> WITH t AS(SELECT 'book' NAME, 100 VALUE FROM dual UNION ALL
      2  SELECT 'book', 200 FROM dual UNION ALL
      3  SELECT 'car', 25 FROM dual UNION ALL
      4  SELECT 'car', 35 FROM dual UNION ALL
      5  SELECT 'book', 300 FROM dual)
      6      SELECT NAME, LTRIM (MAX (SYS_CONNECT_BY_PATH (VALUE, ',')), ',') VALUE
      7        FROM (SELECT NAME, VALUE, ROW_NUMBER () OVER (PARTITION BY NAME ORDER BY VALUE) rn FROM t)
      8  START WITH rn = 1
      9  CONNECT BY PRIOR rn + 1 = rn
    10             AND PRIOR NAME = NAME
    11    GROUP BY NAME;
    NAME VALUE
    book 100,200,300
    car  25,35
    2 rows selected.
    SQL> G.

  • How can i write sql query for this result ?

    Hello Dear,
    Here is the script first.
    CREATE TABLE ACC_TEST(
    AD_ID NUMBER,
    AD_NAME VARCHAR2(50),
    AD_SPM_ID NUMBER);
    /data are
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (136,'Saleh Ahmed',129);
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (142,'Hamidur Rahman',136);
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (124,'Jasim Uddin',null);
    INSERT INTO ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) VALUES (129,'Sazib',124);I Need The Following Result When I Pass A Value Of Ad_Id. For Example I Pass 142 Then Result Should Be
    Select Ad_Id,Ad_Name
    From..
    where ad_id=142
    Ad_Id   Ad_Name
    136     Saleh Ahmed
    129     Sazib
    124     Jasim Uddin
    If I Pass Ad_Id=136 Then Result Should Be
    Ad_Id   Ad_Name
    129     Sazib
    124     Jasim Uddin
    If I Pass Ad_Id=129 Then Result Should Be
    Ad_Id   Ad_Name
    124     Jasim Uddin Database 10G XE
    Any help will be helpful

    Hi,
    HamidHelal wrote:
    WoW ! you acutely got my point. How did you understand that ? lLuck guess. Guessing is usually not the best way to solve problems. It's usually faster and more reliable to say exactly what you want, as well as give an example.
    ittle bit more i want to know, if i want to restrict the output not more then 2, what would be sql ?Now you're not even giviing an example!
    Maybe you want something like this:
    SELECT     ad_id
    ,     ad_name
    FROM     acc_test
    WHERE     LEVEL     BETWEEN 2 AND 3          -- Changed
    START WITH     ad_id     = :target_ad_id
    CONNECT BY     ad_id     = PRIOR ad_spm_id
    ;which will show jsut the parent and the grandparent of the given row.
    I do work with forms developer very much. Sql knowledge is as oracle sql book(cerfitication 9i). But this type of sql isn't available there.
    where can i learn this type of sql ? Different sql then ordinary ?Certification is a different topic entirely.
    There are books and web sites dealing with more advanced techniques. Sorry, I don't know any well enough to recommend them. Some authors (such as Tom Kyte) are consistently good.
    Here are a couple of sites that explain CONNECT BY queries:
    http://www.adp-gmbh.ch/ora/sql/connect_by.html
    http://www.oradev.com/connect_by.jsp

  • How can I write a query for this?

    I have a table as below ,
    room.........date.............inventory
    A..............01/01.................5
    A..............01/02.................5
    A..............01/03.................5
    A..............01/05.................5
    A..............01/06.................5
    A..............01/07.................8
    I want the output as below
    room.....begin_date........end_date......inventory
    A............01/01.................01/03..........5
    A............01/05.................01/06..........5
    A............01/07.................01/07..........8
    Is there any suggestion?
    Thanks
    null

    with x as
    (select 'A' room, to_date ('01/01/2007', 'mm/dd/yyyy') d, 5 i from dual union all
    select 'A' room, to_date ('01/02/2007', 'mm/dd/yyyy') d, 5 i from dual union all
    select 'A' room, to_date ('01/03/2007', 'mm/dd/yyyy') d, 7 i from dual union all
    select 'A' room, to_date ('01/04/2007', 'mm/dd/yyyy') d, 7 i from dual union all
    select 'A' room, to_date ('01/05/2007', 'mm/dd/yyyy') d, 5 i from dual union all
    select 'A' room, to_date ('01/06/2007', 'mm/dd/yyyy') d, 5 i from dual
    select min (d)
         , max (d)
         , min (i)
      from (
    select room
         , d
         , i
         , max (g) over (order by d) mg
      from
    (select room
         , d
         , i
         , case when lead (i) over (partition by grp order by d) = i
           then rownum
           end  g
    from (
    select room
    , d
    , i
    , d - rownum grp
    from x
    order by d
    group by mg

  • 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 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 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 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 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 can I write the loop for this?

    public void currentConnectedPlayers (String[ ] connectedPLayers)
    //connectedPlayers contains the names of players connected to the server.
    //Display the list of connected players, but SELF is not included in the display list
    how will I be able to identify "self" within the loop, in order to exclude myself from beig listed....

    but in coding... i should use "this" instead of
    "self"
    shoudlnt I?!Never "this" is not a string it is a class, only if it extends String Class,
    Since the users are stored in a String array, we need to know what is the information you put in that array is it name, id .
    >
    otherwise got error

  • Write a Query For this

    Hi friend,
    I have a requirement...for complete this i want to your help... I create sample table and sample data here.
    My table is like this :
    create table test1
    ( docid number(10),
    doctyp varchar2(10),
    billno varchar2(10),
    prnno varchar2(10),
    amount number(10)
    My data is :
    insert into test1 values ( D0001, 'BNP05', '101', 'PRN01', 1000);
    insert into test1 values ( D0001, 'BNP05', '101', 'PRN02', 1000);
    insert into test1 values ( D0001, 'BNP05', '101', 'PRN03', 1000);
    insert into test1 values ( D0002, 'BNP05', '102', 'PR01', 100);
    My expected o/p :
    DOCID DOCTYP BILLNO PRNNO AMOUNT
    ================================================
    D0001 BNP05 101 PRN01 1000
    D0001 BNP05 101 PRN02 0
    D0001 BNP05 101 PRN03 0
    D0002 BNP05 101 PR01 100
    If u see it, i dont want to show amount repeatly.... for DOCID, DOCTYP, BILLNO Combination..
    How to achieve this ... ??
    Thanks in advance

    Hi,
    Do you want something like this:
    SQL> select  DOCID, DOCTYP, BILLNO, prnno,
      2          case
      3            when row_number() over(partition
      4                  by
      5                  docid,doctyp,billno
      6                 order by prnno) = 1
      7                 then amount
      8            else null
      9           end   as amount
    10  from test1
    11  order by docid,doctyp,billno;
         DOCID DOCTYP     BILLNO     PRNNO          AMOUNT
             1 BNP05      101        PRN01            1000
             1 BNP05      101        PRN02
             1 BNP05      101        PRN03
             2 BNP05      102        PR01              100
    SQL>

  • How can i write the query for the below output

    Hi,
    I need this kind of output for my report.Please suggest me asap.It's urgent.
    Item Description category subinvcode A B C D....................(All Subinventories)
    1 AAAA FFF 5 8 (Quantity Values for the corresponding subinventories)
    Plz help.

    I still don't have a clue what you're going on about, but here's an example of pivoting that I've knocked up based on your scatty bit of data which may give some hint to you as to what to do....
    SQL> create table inventory as
      2  select 1 as item_id, '0016K8731' as item_desc from dual union
      3  select 2, '0014R0181' from dual;
    Table created.
    SQL>
    SQL> create table sub_inventory as
      2  select 1 as item_id, 'FG_IBM' as sub_item_id, 5 as quantity from dual union
      3  select 1, 'FG_HUN', 4 from dual union
      4  select 1, 'FG_PSA', 12 from dual union
      5  select 2, 'FG_IBM', 1 from dual union
      6  select 2, 'FG_HUN', 17 from dual union
      7  select 2, 'FG_PSA', 3 from dual;
    Table created.
    SQL>
    SQL> select item_desc, max(fg_ibm) as fg_ibm, max(fg_hun) as fg_hun, max(fg_psa) as fg_psa
      2  from (
      3    select i.item_desc,
      4           decode(s.sub_item_id, 'FG_IBM', quantity, null) as fg_ibm,
      5           decode(s.sub_item_id, 'FG_HUN', quantity, null) as fg_hun,
      6           decode(s.sub_item_id, 'FG_PSA', quantity, null) as fg_psa
      7    from inventory i, sub_inventory s
      8    where s.item_id = i.item_id
      9    )
    10  group by item_desc
    11  /
    ITEM_DESC     FG_IBM     FG_HUN     FG_PSA
    0014R0181          1         17          3
    0016K8731          5          4         12
    SQL>

  • I want sql query for this output

    hi guys
    could u tell how can i write sql query for this out put
    i have one table like this
    ID ACCOUTID TAX
    1 1 A
    2 1 B
    3 2 C
    4 2 D
    5 3 E
    7 NULL F
    8 NULL G
    MY OUT PUT MUST BE LIKE THIS
    ID AID TAX
    2 1 A
    4 2 D
    7 NULL F
    8 NULL G
    HERE IN THIS OUTPUT I SHOULD HAVE
    MAXIMAM ID VALUE FOR A REPEATED AID VALUES
    AND
    THE ROWS AID VALUES IS NULL ALSO MUST PAPULATED IN THE OUTPUT.
    I KNOW ONE SOLUTION LIKE THIS
    SELECT MAX(ID),AID,TAX
    FROM TABLE T
    GROUP BY AID,TAX
    UNION ALL
    SELECT ID, AIC,TAX
    FROM TABLE T
    WHERE AID IS NULL;
    BUT I WANT SAME RESULT WITH OUT USING LOGICAL OPERATORS.
    COULD U PLZ TELL A SOL.

    Will this help:
    SQL> with t as
      2    (
      3      select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
      4      select 2, 1, 'B' from dual union all
      5      select 3, 2, 'C' from dual union all
      6      select 4, 2, 'D' from dual union all
      7      select 5, 3, 'E' from dual union all
      8      select 7, NULL, 'F' from dual union all
      9      select 8, NULL, 'G' from dual
    10    )
    11  --
    12  select id, ACCOUTID AID, Tax
    13  from
    14  (
    15    select t.*
    16          ,count(1)       over (partition by t.ACCOUTID) cn
    17          ,row_number()   over (partition by t.ACCOUTID order by id desc) rn
    18    from t
    19  )
    20  where cn > 1
    21  and (rn = 1 or ACCOUTID is null)
    22  /
            ID        AID T
             2          1 B
             4          2 D
             8            G
             7            F
    -- If I leave out the OR condition then you'll get this:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as
      2    (
      3      select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
      4      select 2, 1, 'B' from dual union all
      5      select 3, 2, 'C' from dual union all
      6      select 4, 2, 'D' from dual union all
      7      select 5, 3, 'E' from dual union all
      8      select 7, NULL, 'F' from dual union all
      9      select 8, NULL, 'G' from dual
    10    )
    11  --
    12  select id, ACCOUTID AID, Tax
    13  from
    14  (
    15    select t.*
    16          ,count(1)       over (partition by t.ACCOUTID) cn
    17          ,row_number()   over (partition by t.ACCOUTID order by id desc) rn
    18    from t
    19  )
    20  where cn > 1
    21* and rn = 1
    SQL> /
            ID        AID T
             2          1 B
             4          2 D
             8            G
    --which follows the description you've given, but not the output

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

Maybe you are looking for