Help needed in a Query

I have a table TAB that has two colums. COL1 and COL2. Both are composite Primary key.
The data is as
COL1 COL2
1 C
2 C
3 C
4 G
5 G
1 G
3 G
6 G
7 G
I need to find out those COL1 values whose COL2 values are C and G. Ex
COL1 COL2
1 C
3 C
1 G
3 G
So i need the following op
COL1
1
3
Please help me to solve this query.
Regards.
Message was edited by:
SID

and what have you tried ????
SQL> With t As
  2    (
  3    Select 1 c1, 'C' c2 From DUAL Union All
  4    Select 2,     'C'   From DUAL Union All
  5    Select 3,     'C'   From DUAL Union All
  6    Select 4,     'G'   From DUAL Union All
  7    Select 5,     'G'   From DUAL Union All
  8    Select 1,     'G'   From DUAL Union All
  9    Select 3,     'G'   From DUAL Union All
10    Select 6,     'G'   From DUAL Union All
11    Select 7,     'G'   From DUAL
12    )
13    Select t.c1, t.c2
14    From
15    t,
16    (
17    Select c1, c2
18    From t
19    Where c2 = 'C'
20    ) c,
21    (Select c1, c2
22     From t
23     Where c2 = 'G'
24     ) g
25  Where t.c1 = c.c1
26  And   t.c1 = g.c1
27  --And   c.c2 = g.c2;
        C1 C2
         1 C
         1 G
         3 C
         3 G
SQL>
/*using analytical functons*/
SQL>
SQL> With t As
  2    (
  3    Select 1 c1, 'C' c2 From DUAL Union All
  4    Select 2,     'C'   From DUAL Union All
  5    Select 3,     'C'   From DUAL Union All
  6    Select 4,     'G'   From DUAL Union All
  7    Select 5,     'G'   From DUAL Union All
  8    Select 1,     'G'   From DUAL Union All
  9    Select 3,     'G'   From DUAL Union All
10    Select 6,     'G'   From DUAL Union All
11    Select 7,     'G'   From DUAL
12    )
13   select c1, c2
14         from ( select c1,c2, case when c2 = 'C' then count(decode(c2,'G',1)) over (partition by c1)
15                                    when c2 = 'G' then count(decode(c2,'C',1)) over (partition by c1)
16                               else 0 end count                           
18                from t
19            )
20      where Count != 0
21  /
        C1 C2
         1 C
         1 G
         3 C
         3 GMessage was edited by:
Nicloei W

Similar Messages

  • Help needed for writing query

    help needed for writing query
    i have the following tables(with data) as mentioned below
    FK*-foregin key (SUBJECTS)
    FK**-foregin key (COMBINATION)
    1)SUBJECTS(table name)     
    SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
    2           02           Computer Science
    3           03           Physics
    4           04           Chemistry
    5           05           Mathematics
    7           07           Commerce
    8           08           Computer Applications
    9           09           Biology
    2)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
    383           S1      9           4           2           3
    384           S2      4           2           5           3
    ---------I actually designed the ABOVE table also like this
    3) a)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
    383           S1
    384           S2
    b)COMBINATION_DET
    COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
    1               383          9
    2               383          4
    3               383          2
    4               383          3
    5               384          4
    6               384          2          
    7               384          5
    8               384          3
    Business rule: a combination consists of a maximum of 4 subjects (must contain)
    and the user is less relevant to a COMB_NAME(name of combinations) but user need
    the subjects contained in combinations
    i need the following output
    COMB_ID COMB_NAME SUBJECT1 SUBJECT2      SUBJECT3      SUBJECT4
    383     S1     Biology Chemistry      Computer Science Physics
    384     S2     Chemistry Computer Science Mathematics Physics
    or even this is enough(what i actually needed)
    COMB_ID     subjects
    383           Biology,Chemistry,Computer Science,Physics
    384           Chemistry,Computer Science,Mathematics,Physics
    you can use any of the COMBINATION table(either (2) or (3))
    and i want to know
    1)which design is good in this case
    (i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
    good method to link with same table but if 4 subjects only(and must) comes
    detail table is not neccessary )
    now i am achieving the result by program-coding in C# after getting the rows from oracle
    i am using oracle 9i (also ODP.NET)
    i want to know how can i get the result in the stored procedure itsef.
    2)how it could be designed in any other way.
    any help/suggestion is welcome
    thanks for your time --Pradeesh

    Well I forgot the table-alias, here now with:
    SELECT C.COMB_ID
    , C.COMB_NAME
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
    FROM COMBINATION C;
    As you need exactly 4 subjects, the columns-solution is just fine I would say.

  • Help needed for SQL query

    hello ,
    I am a beginner in terms of writing sql queries. I hope some body can help me out.
    I have two tables
    mysql> desc user_group_t;
    ---------------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    ---------------------------------------------------+
    | userAccountId | char(8) | | PRI | | |
    | groupId | char(8) | | PRI | | |
    ---------------------------------------------------+
    2 rows in set (0.00 sec)
    mysql> desc group_t;
    ---------------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    ---------------------------------------------------+
    | id | char(8) | | PRI | | |
    | name | char(50) | YES | | NULL | |
    | email | char(100) | YES | | NULL | |
    | description | char(254) | YES | | NULL | |
    | parentId | char(8) | YES | | NULL | |
    | creatorId | char(8) | YES | | NULL | |
    | createDate | char(20) | YES | | NULL | |
    | updateDate | char(20) | YES | | NULL | |
    | updatorId | char(8) | YES | | NULL | |
    ---------------------------------------------------+
    9 rows in set (0.00 sec)
    what I want is list of all groups with id,name and #of members(which is the # of rows in the user_group_t for any given id). Importantly I need the groups with 0 members also to be listed. In short my output should contain exactly the same number of rows as in group_t table with an additional column indicating # of members for that group.
    Any help would be greatly appreciated.
    Thanks in Advance.
    -Vasanth

    Thanks Donald,
    Actually I figured it out, with the following query:
    select id,name,sum(if(groupid is not null,1,0)) as members from group_t left join user_group_t on id=groupid group by id;
    I tried your solution, but mysql says there is an error at '+' . Anyway I modified your solution to the one below and it worked.
    select a.id, a.name, count(b.groupid) from group_t a left join user_group_t b on a.id=b.groupid group by a.id, a.name;
    I tried that before but then I used Count(*) instead of count on groupid. Your solution is elagant and I will go with yours.
    Thanks again.
    Vasanth

  • Urgent help needed on 1 query

    Hello All,
    I have just started working in PL/SQL,
    I need some help on 1 urgent issue.
    i have a table lets say which has structure and values like below:
    ID Data Key Data Value
    1 Firstname X
    2 Lastname Y
    3 Middlename Z
    but my query shd return me data having firstname ,middlenale and last name as column names and lvalues like lsited below:
    Firstname Middlename Lastname
    X Y Z
    Please help and i really appreciate for your time and help!!!!!!!!!!
    Thanks and Regards

    Urgent? I don't think so.
    However, as others have mentioned, what groups the items together so that the relationship is known between them?
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as id, 'Firstname' as data_key, 'Fred' as data_val from dual union all
      2             select 2, 'Surname', 'Bloggs' from dual union all
      3             select 3, 'Middlename', 'J' from dual union all
      4             select 4, 'Firstname', 'John' from dual union all
      5             select 5, 'Surname', 'Doe' from dual union all
      6             select 6, 'Middlename', 'D' from dual)
      7  --
      8  select id-decode(data_key,'Surname',1,'Middlename',2,0) as id
      9        ,max(decode(data_key,'Firstname',data_val)) as Firstname
    10        ,max(decode(data_key,'Middlename',data_val)) as Middlename
    11        ,max(decode(data_key,'Surname',data_val)) as Surname
    12  from t
    13* group by id-decode(data_key,'Surname',1,'Middlename',2,0)
    SQL> /
            ID FIRSTN MIDDLE SURNAM
             1 Fred   J      Bloggs
             4 John   D      Doe
    SQL>This example assumes that a Firstname, Surname and Middlename appear in that order with sequential ID's, such that the ID for Surname is always 1 more than the ID for it's associated Forename and the ID for Middlename is always 2 more than the associated Forename.

  • Help needed in select query

    Hi,
    I need to select the max time for the transaction using the below query. I’m able to get the o/p. Here the problem is I need to fetch the corrletorid (primary key) as well. if try to get that I’m getting the o/p like case2.
    I want the o/p to be like case 1 with the corrleator id . plz help me to get the o/p.
    Case 1: select b.TransactionName, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname
    TRANSACTIONNAME MAXTIME
    FINT3 12/10/2007 19:53:09.042000
    FINT 12/10/2007 19:31:07.042000
    FINT2 12/10/2007 19:31:07.042000
    SQL> /
    Case 2: select b.TransactionName,b.correlatorid, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname,b.correlatorid
    SQL> /
    TRANSACTIONNAME CORRELATORID AVERAGE
    FINT2 102 12/10/2007 19:31:07.042000
    FINT3 108 12/10/2007 19:53:09.042000
    FINT3 103 12/10/2007 19:31:07.042000
    FINT 101 12/10/2007 19:31:07.042000
    in the above output i should have only record(max time) for FINT3.
    Thank

    Sharma,
    Please find the below sample data(insert stmt and create table):
    ======================================
    create table trandetails(
    correlatorid varchar2(20) CONSTRAINT correlatorid_FKey REFERENCES Subtrandetails(correlatorid),
    username varchar2(25) NOT NULL,
    applicationname varchar2(25) NOT NULL,CONSTRAINT composite1_pkey1 PRIMARY KEY(correlatorid ,applicationname));
    create table Subtrandetails(
    correlatorid varchar2(20) PRIMARY KEY,
    PCORRELATORID      varchar2(20),
    TransactionName varchar2(25) NOT NULL,
    Machinename varchar2(15) NOT NULL,
    STARTDATE timestamp NOT NULL,
    ENDDATE timestamp NOT NULL,
    SourceName varchar2(25),
    FunctionName varchar2(25),
    LOC number(5),
    CONTEXTPROPERTY1 varchar2(25),
    CONTEXTPROPERTY2 varchar2(25),
    CONTEXTPROPERTY3 varchar2(25),
    TransactionStatus varchar2(25) NOT NULL CONSTRAINT Transaction1_Status_chk Check (TransactionStatus in ('Success', 'Failure', 'Abort')));
    INSERT INTO trandetails VALUES ('11','FINAPP','ANUAPP1');
    INSERT INTO trandetails VALUES ('13','FINTEST','ANUAPP2');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('10','1','ARM','blrkec95931d','10-DEC-07 03.24.07.042000 PM','10-DEC-07 03.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('11','1','ARM1','blrkec95931d','10-DEC-07 04.24.07.042000 PM','10-DEC-07 04.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('12','1','ARM2','blrkec95931d','10-DEC-07 05.24.07.042000 PM','10-DEC-07 05.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('13','1','ARM3','blrkec95931d','10-DEC-07 06.24.07.042000 PM','10-DEC-07 06.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('14','1','ARM4','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('101','11','FINT','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('102','11','FINT2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('103','11','FINT3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('104','13','SAP1','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('105','13','SAP2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('106','13','SAP3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('107','13','SAP2','blrkec95931d','10-DEC-07 07.2.10.042350 PM','10-DEC-07 07.50.10.042050 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('108','11',' FINT3 ','blrkec95931d','10-DEC-07 07.16.07.042000 PM','10-DEC-07 07.53.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('109','108','FINT3','blrkec95931d','10-DEC-07 07.20.07.042000 PM','10-DEC-07 07.59.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('110','108','FINT3','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('111','108','FINT4','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('112','108','FINT5','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('113','108','FINT6','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('114','108','FINT7','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    ======================================
    Thanks.

  • Help need in hierarchy query

    Hi,
    I need to display the parent child nodes in the hierarchical manner and i need to list the user under their hier name in the same hierarchical structure. table structures are all as follows.
    user table:
    * userid name*
    100 john
    101 shaddy
    102 sandy
    103 Kalinich
    104 king
    105 Teresa
    106 Clinia
    user hier table :
    userid  hier name
    100 node1
    101 node2
    102 node1
    103 node2
    104 parent
    105 node4
    106 node
    hier table:
    id hier name parent_id
    1 parent
    2 node 1
    3 node1 2
    4 node2 2
    5 node3 1
    6 node4 5
    7 node5 5
    o/p :
    104 king
    106 clinia
    100 john
    102 sandy
    103 Kalinich
    101 shaddy
    105 terresa
    even we dont have entry in user hier and user table for node3 we need to display them child users under the "parent" hier name and need to ignore the child nodes which dont have users under them i.e) need to ignore node5 in the output. below is the query which I have tried.
    SELECT NAME,u.name
    FROM user_hier n,hier u,user a
    WHERE a.user_id (+) = u.user_id
    AND u.name (+) = n.name
    START WITH n.name = 'parent'
    CONNECT BY PRIOR n.node_id= n.parent_node_id;
    Help me on this.
    Thanks in advance
    Edited by: Vi on Apr 30, 2012 6:10 AM

    No you haven't. Either post create table statements or set up your data with a WITH clause, something like the following example:
    with USER_TABLE as (
      select 100 userid, 'john' name from dual union all
      select 101 userid, 'shaddy' name from dual union all
      select 102 userid, 'sandy' name from dual union all
      select 103 userid, 'Kalinich' name from dual union all
      select 104 userid, 'king' name from dual union all
      select 105 userid, 'Teresa' name from dual union all
      select 106 userid, 'Clinia' name from dual
    select * from USER_TABLE
        USERID NAME
           100 john
           101 shaddy
           102 sandy
           103 Kalinich
           104 king
           105 Teresa
           106 Clinia
    7 rows selected.

  • Expert help needed with tricky query

    I have a query database with a real simple schema but a tricky requirement: i need to display records with a simple select but then filter the result based on the authority/access level of the user making the query.
    The source data is held in a table with just the following columns:
    SRCTABLE:
    subject_ID
    date
    data_ID
    data_item
    All column types are text strings and the first 3 are a composite key. There are 10s of millions of records in the table.
    The access authorization is held in another table with the following columns:
    ACCTABLE:
    data_ID
    access1
    access2
    accessn
    The ellipsis means there are as many (boolean type) access1...n columns as there are distinct access levels to the source data.
    The table contains one row for each distinct data_ID appearing in the source table. On each row the TRUE values in the access1...n columns indicate authorization to see the data item and the filter should leave that row in the result set.
    The question then is how to write the query statement? It is assumed that the access id (i.e. the relevant column) is known when the query is made.
    Something like
    SELECT data_item FROM SRCTABLE
    WHERE subject_ID="xxx" AND date = "1/1/2000";
    would do it except for the need to filter each row based on the access authorization of the user.
    Any help would be appreciated.

    Thanks everybody for responding.
    APC has a good point about really protecting every single item type separately. Unfortunately this is precisely the case. The security in this case is not oriented to increasing security in a levels oriented way. Rather each kind of item is protected by a need to know type security related to that particular item. Users are classified by their need to know a combination of the item types and those combinations are not in any sense consistent (and there will be new classes over time). This way access control necessarily becomes a matrix of item types vs access classes.
    Fortunately this particular database does not exist yet so i am free to solve the problem in any way that fulfills the requirement. This is just the suggested form. I am not entirely happy with it hence the question on this forum in the first place.
    So, i appreciate it should you have any further suggestions for optimal solution to handle the requirements. Again, those are:
    1. A query that returns the data_items for a given ID and date (this is dead simple)
    2. A filter (preferably in the query) that filters out those data_items the current user (his/her access class is known) is not authorized to see.
    3. The plan calls for a table listing every possible item type with a column for each access class, enumerating the items allowed for that class. Any other solution to this issue would be acceptable provided it is capable to independently validate any single item type against any access class.
    I hope this makes sense.

  • Help needed in building query

    Tab1
    Parent       Child       sa l
    P1     A1       4000
    A1     A       1000
    A1     B       4000
    A     X       1000
    A     Y         2000
    B     X1        1000           
    B     X2       3000I need to build a query that will retrieve the value for each child as the sum of the salaries of all its child in a single query.
    That is
    For Sal P1 = Sal A1 + all child of A1 and its child
         For A1 = Sal A1 + all child of A1 and its child ( A+B+X+Y+X1+X2)
    Like it should sho all the records with the count .. please help

    This is not so simple since it is not really clear in your data set whether the sal belongs to the parent or to the child. I assume it's the salary of the child, in which case the salary of P1 is missing. The best option is to fix the data model and have two tables: one containing the element and sal, and another table containing just the relationships. To fix this issue I introduced a dummy record for P1 and salary 0.
    SQL> with t2 as
      2  ( select connect_by_root(child) cbr
      3         , sal
      4      from (select * from t union all select null,'P1',0 from dual)
      5   connect by parent = prior child
      6  )
      7  select cbr child
      8       , sum(sal)
      9    from t2
    10   group by cbr
    11  /
    CHILD    SUM(SAL)
    X1           1000
    A1          16000
    X2           3000
    P1          16000
    Y            2000
    X            1000
    A            4000
    B            8000
    8 rows selected.Regards,
    Rob.

  • Help needed in writing query

    Hi,
    Could anyone help me in writing below query without syntax errors.
    I tried but no luck
    select xmlelement("g", XMLATTRIBUTES(g.contentgroup_id as "id",g.groupname as "label",
    (select xmlagg(xmlelement ("c",XMLATTRIBUTES(c.title as "title",c.content_id as "id")))) as "A"))
    as "A" from
    (SELECT g.contentgroup_id AS id, g.groupname AS label, c.title AS label, c.content_id AS id
    FROM content_ec c FULL OUTER JOIN contentgroup_ec g ON c.group_id = g.contentgroup_id
    oRDER BY g.groupname ,c.title ASC );
    Any help really appreciated.
    Thanks

    Few tips to get your question answered here
    1. Give your database version. Some thing that does not work in one version works fine in the next. And 8i,9i or 10g is not version. best way to give the version is to query your v$version table like this.
    SQL> select * from v$version where rownum = 1
      2  /
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod2. You should understand we don't have what you have, meaning you should provide your data structure and some sample data for us to help.
    3. "I got an error"... "Its not working"... and the list goes on. Sentences like this does not help. If you got a error past the entire error. If stuff does not work, tell us the details.
    4. Just don't throw some output and say i want it. Please explain to every one how you derive it.
    5. And the most important thing. Use \...\ tag to format. Please.. Please.. Please.. use it. It helps every one a lot. When you use it your SQL looks some thing like this.
    SELECT xmlelement("g", XMLATTRIBUTES(g.contentgroup_id as "id",g.groupname as "label",
         (select xmlagg(xmlelement ("c",XMLATTRIBUTES(c.title as "title",c.content_id as "id")))) as "A")) as "A"
       FROM (SELECT g.contentgroup_id AS id,
                 g.groupname AS label,
                 c.title AS label,
                 c.content_id AS id
            FROM content_ec c
            FULL OUTER JOIN contentgroup_ec g
              ON c.group_id = g.contentgroup_id
           ORDER BY g.groupname ,c.title ASC );6. And also do search this forum. Most of your my queries are answered by simple search.
    Thanks,
    Karthick.

  • Help Needed In SQL Query

    HI All,
    Oracle sql clarification required
    Sample Table:
    empno empname Job mgr_id hire_date salary deptno
    7788 SCOTT ANALYST 7566 19-APR-87 3000 20
    7902 FORD ANALYST 7566 03-DEC-81 3000 20
    7934 MILLER CLERK 7782 23-JAN-82 1300 10
    7900 JAMES CLERK 7698 03-DEC-81 950 30
    7369 SMITH CLERK 7902 17-DEC-80 800 20
    7876 ADAMS CLERK 7788 23-MAY-87 1100 20
    Need "single / one" sql for this requirement statement:
    There will be 2 drop down boxes (1st - Job list, 2nd - empno) in the form in which the following result set is expected
    1) When user selects value from 1st drop down box (job) as "ANALYST" leaving the second drop down unselected, the result expected is 2 (no. of rows for that job)
    2) When user selects value from 1st drop down box (job) as "ANALYST" and the value from 2nd drop down box as 7902, the result expected is 1 (no of rows for that job and empno)
    Sqls which I have tried from my side (given below) didn't give the expected result and please do help me in correcting this
    select count(1) from scott.emp where job='ANALYST' and ( empno = :empno or empno is null ) ;
    Please help for this requirement. Any help is deeply appreciated.
    Thanks
    Zaheer

    Hi,
    welcome to the forum.
    Please read SQL and PL/SQL FAQ
    When you put some code or output please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    For your question the following will both work:SQL> select * from emp
    where job='ANALYST' and (empno =:empno or :empno is null)
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7788 SCOTT ANALYST 7566 19/04/1987 00:00:00 3000 20
    7902 FORD ANALYST 7566 03/12/1981 00:00:00 3000 20
    2 rows selected.
    SQL> select * from emp
    where job='ANALYST' and empno =NVL(:empno, empno)
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7788 SCOTT ANALYST 7566 19/04/1987 00:00:00 3000 20
    7902 FORD ANALYST 7566 03/12/1981 00:00:00 3000 20
    2 rows selected.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help needed in SORTING query

    I have a table having single column c1 of varchar2(10) and have stored these values in the table.
    A0
    A1
    A01
    A100
    A101
    A102
    B10
    B99
    B100
    B101
    B102
    100
    120
    200
    I need to sort them in the order as given, can someone help please.
    Thanks

    select c
    from (select c, substr(c,1,1) c1, length(c) len, substr(c,2) c2 from xx)
    order by case when ascii(c1) < 65
    then ascii(c1)+100
    else ascii(c1)
    end, len, c2

  • Help needed in join query

    Hi Friends,
    I am not experienced sql developer, so can u guys help me . I want to display name from foll. tables
    Table A
    KeyID number PK
    Name
    Table B
    BID number pk
    KeyID
    ABC
    Table C
    CID - PK
    KeyID
    XYZ
    I want to display name from table A for matching keyid between Table A and B. If KeyID is null in Table B then I want to match with Table A with C.
    How can I write this query?

    But isn't that what Alessandro's query is doing ?
    Thanks for your help, but there is still one catch.
    What I want to do is, take key_id from table b, if it
    is null then take key_id from table c ...
    >>           when b.key_id is not null then
                   b.abc
              else
                        select xyz
                        from c ...
    ... and then match
    with table a
    >>                     ... where c.key_id = a.key_id
         end ...
    to get name from table a.
    >> select key_id,
         a.name,
         case
    Can you help me out ?
    I am trying ur existing query, ...Did you face any problem before posting ?
    pratz

  • Help needed in pricelist query

    Hi All,
    I want to know the join between tables qp_list_lines, qp_pricing_attributes and mtl_system_items_b.
    Currently the query which we are using is -
    SELECT qpll.list_header_id, qpll.list_line_id,
    qpll.start_date_active start_date, qpll.end_date_active end_date,
    qpll.product_precedence, qppr.product_attribute,
    qppr.product_attribute_context, qppr.product_attr_value
    FROM qp_list_lines qpll, qp_pricing_attributes qppr, mtl_system_items_b msi
    WHERE qppr.list_line_id = qpll.list_line_id
    AND qpll.list_header_id = :p_list_header_id
    AND qpll.list_line_type_code IN ('PLL', 'PBH')
    AND qppr.pricing_phase_id = 1
    AND qppr.qualification_ind IN (4, 6, 20, 22)
    AND qpll.pricing_phase_id = 1
    AND qpll.qualification_ind IN (4, 6, 20, 22)
    AND qppr.pricing_attribute_context IS NULL
    AND ( msi.segment1 LIKE (UPPER (:p_product_number) || '%')
    OR :p_product_number IS NULL
    AND TO_CHAR (msi.inventory_item_id) = qppr.product_attr_value
    AND msi.organization_id = 507;
    But, this query fails when the product_attr_value does not have the inventory_item_id and then the join TO_CHAR (msi.inventory_item_id) = qppr.product_attr_value fails which results in no rows are returned by the query.
    Is there a way by which we can get data for Price Lists which do not have item ID.
    Any quick help in this would be highly appreciated.
    Regards,
    Shruti

    >
    SELECT qpll.list_header_id,
    qpll.list_line_id,
    qpll.start_date_active start_date,
    qpll.end_date_active end_date,
    qpll.product_precedence,
    qppr.product_attribute,
    qppr.product_attribute_context,
    qppr.product_attr_value
    FROM qp_list_lines qpll,
    qp_pricing_attributes qppr,
    mtl_system_items_b msi
    WHERE qpll.list_line_id =qppr.list_line_id
    AND qpll.list_header_id = :p_list_header_id
    AND qpll.list_line_type_code IN ('PLL', 'PBH')
    AND qppr.pricing_phase_id = 1
    AND qppr.qualification_ind IN (4, 6, 20, 22)
    AND qpll.pricing_phase_id = 1
    AND qpll.qualification_ind IN (4, 6, 20, 22)
    AND qppr.pricing_attribute_context IS NULL
    AND (msi.segment1 LIKE (upper(:p_product_number) || '%') OR
    :p_product_number IS NULL)
    AND qppr.product_attr_value= to_char(msi.inventory_item_id(+))
    AND msi.organization_id(+) = 507

  • Help needed in MV Query

    Hello,
    I have created a MV as follows:
    CREATE MATERIALIZED VIEW Test1_MV
    BUILD IMMEDIATE
    REFRESH COMPLETE
    ENABLE QUERY REWRITE
    AS
    SELECT b.Customer_ID,
    j.MONTH_END_DATE,
    (AVG(sum(COUNT *(case when (m.DIM1_DSC ='ABC') then 1 else 0 end)))OVER (ORDER BY b.Customer_ID, j.MONTH_END_DATE ROWS 5 PRECEDING)) AS AVG_ABC_Count,
    (AVG(sum(AMT *(case when (m.DIM1_DSC ='ABC') then 1 else 0 end)))OVER (ORDER BY b.Customer_ID, j.MONTH_END_DATE ROWS 5 PRECEDING)) AS AVG_ABC_Amount,
    (AVG(sum(COUNT *(case when (m.DIM1_DSC ='DEF') then 1 else 0 end)))OVER (ORDER BY b.Customer_ID, j.MONTH_END_DATE ROWS 5 PRECEDING)) AS AVG_DEF_Count,
    (AVG(sum(AMT *(case when (m.DIM1_DSC ='DEF') then 1 else 0 end)))OVER (ORDER BY b.Customer_ID, j.MONTH_END_DATE ROWS 5 PRECEDING)) AS AVG_DEF_Amount,
    sum(COUNT *(case when (m.DIM1_DSC ='ABC') then 1 else 0 end)) as Cumm_ABC_Count,
    sum(AMT *(case when (m.DIM1_DSC ='ABC') then 1 else 0 end)) as Cumm_ABC_Amount,
    sum(COUNT *(case when (m.DIM1_DSC ='DEF') then 1 else 0 end)) as Cumm_DEF_Count,
    sum(AMT *(case when (m.DIM1_DSC ='DEF') then 1 else 0 end)) as Cumm_DEF_Amount
    FROM
    DIM_CUSTOMERTABLE b,
    DM_TIME j,
    DIM2_TABLE k,
    DIM3_TABLE l,
    DIM1_TABLE m,
    FACT_TABLE cd
    WHERE
    cd.CUSTOMER_ID = b.CUSTOMER_ID
    AND cd.DATE_ID = j.MONTH_ID
    AND cd.DIM2_ID = k.DIM2_ID
    AND cd.DIM3_ID = l.DIM3_ID
    AND cd.DIM1_ID = m.DIM1_ID
    AND j.YEAR_DSC in('2007','2008')
    GROUP BY b.CUSTOMER_ID, j.MONTH_END_DATE
    ORDER BY b.CUSTOMER_ID, j.MONTH_END_DATE;
    I have a problem..
    My Fact Table has only one row for a customer_Id say 123 i.e., it has data for only DIM1 of data for the year 2007 as follows:
    AMT     DATE_ID     DIM1_ID     DIM2_ID     DIM3_ID     COUNT     CUSTOMER_ID
    5310.85     2007.5     2     2     2     1     123
    So when i query the MV, i should get AVG_ABC_Count and AVG_ABC_Amount should be same as Cumm_ABC_Count and Cumm_ABC_Amount. Because average of one value is the same value itself..But I am getting different values for Average and Cummulative.
    I am grouping by Customer_Id and Date. But why is it that the data is differing.

    Please somebody help me with this..I am stuck at this point..I am not able to find out the reason why i am getting the results like this..If anybody has any idea, will be very helpful..

  • Help needed in resolving query issue

    Hello all,
    Would appreciate any help on the following issue.
    Our process has a stored procedure, which used to take 6 mins to run.
    We are not sure what changed at what level, but now the query goes on forever( till database shuts down or we kill it), and never returns any result. Also, this is not consistent at all times. Sometimes(!!), it brings back results in expected time.
    Apparently nothing changed in the database.
    We checked and the query where it gets stuck is as follows:
    select a.x,
    b.y,
    c,z
    from a,b,c where
    b.header_id =a.header_id and c.property_id =a.property_id(+) and b.status_id in (1,0) and a.date(+)>c.date;
    It does not give any error or any mesg, when it reaches this query, and just hangs in there( Mind this was a working query since last 2 months)
    We are at a total loss at the inconsistent behaviour of this.
    Any help or advise would be greatly appreciated
    Thanks
    Aparajita

    I recommend you to post this as well here:
    Forums Home » Oracle Technology Network (OTN) » Products » Database » SQL and PL/SQL
    Discussion of Oracle SQL and PL/SQL issues
    PL/SQL
    Joel Pérez

Maybe you are looking for

  • Re: HP Expert Day - January 15-16, 2014: Got questions? Ask the Experts!

    (request moved to own topic) HP Officejet Pro 8500 Printer tries to align itself after every print job, but fails Ink streaking somewhat despite recently replacing print cartridges and heads and multiple printhead cleaning cycles Calibrated linefeeds

  • Auxiliary channel allocation in TSPITR with RMAN-managed instance

    Hi, I'm trying do perform TSPITR with RMAN-managed auxiliary instance. All backups are stored on tape. I need to send MML environment values while allocating auxiliary channel to connect to correct NetWorker server and send other NetWorker parameters

  • Audio only with Airplay on iPhone

    Why can't I airplay videos directly from my iPhone 4S (on iOS 6) to my Apple TV. I only get audio and need to enable mirroring to see it, but the quality is poor this way. I can airplay videos from my iPad 3 directly. Help please...

  • 500 Internal Server Error OracleJSP: JSP Error: Exception:java.lang.NullPoi

    500 Internal Server Error OracleJSP: JSP Error: Request URI:/ForecastVsActualWithProgressBarWebApp/htdocs/forecastvsactualportlet/processing.jsp Exception: java.lang.NullPointerException at java.net.URLClassLoader$1.run(URLClassLoader.java:190) at ja

  • How do you create a new mailbox

    Hi, I have an iPhone 5 running iOS 8.1. I also have Verizon webmail which I access via the iPhone's Mail app. I am trying to create a new mailbox in order to store certain emails on my iPhone somewhere besides the Inbox. In the Mail app and at Mailbo