Need a query help

hii
i need a query help
i have two tables
the 1st table will look like this
associate id weekid no.of. hours
4000 810 40
4000 820 30
4000 830 60
4000 840 70
2nd table will look like this
associate id weekid no.of.hours
4000 810 40
4000 820 70
4000 830 130
4000 840 200
so when i subtract the last two records frm each other in the second table the value should be equal to the no.of.hours in the first table.. for example
the query shud consider the last record and one before the last record and the difference between two records shud be equal to the value in the 1st table
for example
consider week id 830 and 840
in second table 830=130
840=200
when u subtraced both values the difference shud be equal to value in the 1st table for tht week id
1 ---->>>> 840 - 830
=200 - 130
=70
in first table 840 has 70 hrs
like this it shud check with all records and it shud return only the records which are not equal
regards
srikanth

This..?
sql>select * from t1;
A_ID W_ID HRS
4000  810  40 
4000  820  30 
4000  830  60 
4000  840  70 
4000  850  80 
sql>select * from t2;
A_ID W_ID HRS 
4000  810  40 
4000  820  70 
4000  830  130 
4000  840  200 
4000  850  260 
sql>
select a_id,w_id,hrs,sum_hrs
from(
select t1.a_id a_id,t1.w_id w_id,t1.hrs hrs,t2.hrs sum_hrs,
       t2.hrs - nvl(lag(t2.hrs)  over(order by t1.w_id),0) diff
from t1,t2
where t1.w_id = t2.w_id)
where diff != hrs;
A_ID W_ID HRS SUM_HRS 
4000  850  80  260                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Need SQL Query Help

    I need help combining two queries into one. This is what I
    have now:
    <CFQUERY NAME="getInfo" datasource="myDS"
    BLOCKFACTOR="100">
    SELECT
    status.status_doc_id,
    status.date_accepted,
    status.date_received,
    document_main.document_main_doc_type,
    document_main.document_main_doc_id,
    document_main_account_id,
    document_main_company_account_id,
    document_main_period_of_report,
    users_account.client_name,
    users_account.account_type
    FROM
    status,
    document_main, users_account
    WHERE
    status.filing_status_user_id = '2'
    AND status.Statustype = 'Live'
    AND status.Currentstatus = 'Accepted'
    AND status.status_doc_id =
    document_main.document_main_doc_id
    AND users_account.account_id =
    document_main.document_main_company_account_id
    </CFQUERY>
    <CFQUERY NAME="getStuff" datasource="myDS"
    BLOCKFACTOR="100">
    SELECT
    users_account.client_name,
    FROM
    users_account
    WHERE
    account_id = '#getInfo.document_main_account_id#'
    AND account_type = 'Individual'
    </CFQUERY>
    The problem is that the account_id referred to in the
    users_account table can be either a Company or an Individual. So in
    my html table the output would list both. A co-worker suggested a
    UNION ALL and to alias the client_name fields. But that query seems
    to ignore the alias after the union.
    Can anyone help me out?

    Thanks for your help Dan.
    I added this to the query:
    CASE users_account.account_type
    WHEN 'Company' THEN users_account.client_name
    END AS COMPANYNAME,
    CASE users_account.account_type
    WHEN 'Individual' THEN users_account.client_name
    END AS IndiNAME
    The problem I have is that because of:
    AND users_account.account_id =
    document_main.document_main_company_account_id
    the output is empty for "IndiNAME".
    Users_account.account_id can refer to a record
    with"individual" or "company" as the account type. So in the same
    record in document_main, document_main_account_id refers back to an
    individual while document_main_company_account_id refers back to a
    company account.
    So of course if I change the above to:
    AND users_account.account_id =
    document_main.document_main_account_id
    then "COMPANYNAME" is empty in the output.
    I can't figure out how to get those two values without one or
    the other being empty (or breaking the link altogether from the
    document_main table to the users_account table).

  • I need sql query help

    I have 5 tables.i want to select one respective record from 5 table .But i will pass only one argument...
    what is the query for that..................

    I didn't understand that that's why i made it
    again.If you ask a question and you don't understand the answer, then you should ask for an explanation of the answer.
    If you get an explanation and you still don't understand, then maybe that is an indication that you don't have enough knowledge of the basics. In this case, perhaps you should try to read a book on SQL and relational database theory.
    Myself only asked that question also.
    Now also i am asking u r able to solve this question
    or not.As I said, I will read the other thread (where you have started to get help) and if I have anything to add, I will post there.

  • Need a query for access tables

    Hi
    I need a query , help please:
    table1:
    id              description                  serial                    
    1                des1                           ser1
    2                des2                           ser2
    3                des3                           ser3
    table2:
    id            id1(id of table1)                date                
    stat
    1              1                                      
    2001                 A
    2              1                                      
    2008                 N
    3              2                                      
    2010                 A
    4              1                                      
    2012                 F
    ==============
    i need this data structure: (stat column must return for maximum date of id1 from table2)
    id(from table1)            serial(from table1)                  stat(from table2)
    1                                    ser1                
                           2012
    2                                    ser2             
                              2010
    3                                    ser3             
                               Null

    maybe you can try this.
    declare @t1 table
    (id int,[description] varchar(50),serial varchar(10))
    declare @t2 table
    (id int,id1 int,[date] char(4),stat char(10))
    insert into @t1 values
    (1,'des1','ser1'),
    (2,'des2','ser2'),
    (3,'des3','ser3')
    insert into @t2 values
    (1,1,'2001','A'),
    (2,1,'2008','N'),
    (3,2,'2010','A'),
    (4,1,'2012','F')
    select a.id,a.serial,max(b.date)
    from @t1 a
    left join @t2 b
    on a.id = b.id1
    group by a.id,a.serial
    | SQL PASS Taiwan Page |
    SQL PASS Taiwan Group
    |
    My Blog

  • Help needed in Query

    I have one table Prd_mst, I need a query or function where whenever i pass the child_id into query or function i get the Parent_id of that
    example Data is below :-
    P_ID,P_NAME,C_ID
    null,Computer,1
    1,KeyBoard,2
    1,Mouse,3
    1,Mother Board,4
    3,Scroll Mouse,5
    3,Optical Scroll Mouse,6
    3,Fibre Scroll Mouse,7
    2,Multimedia Key Board,8
    2,Cordless Key Board,10
    2,Normal Key Board,9
    4,586 Mother Board,13
    4,386 Mother Board,11
    4,486 Mother Board,12
    4,P1 Mother Board,14
    4,P2 Mother Board,15
    4,P3 Mother Board,16
    4,P4 Mother Board,17
    14,533 Mhtz P1 CPU,19
    14,433 Mhtz P1 CPU,18
    19,533 Mhtz P1 CPU With 100Mhtz BUS,20
    19,533 Mhtz P1 CPU With 133Mhtz BUS,21
    18,433 Mhtz P1 CPU With 100Mhtz BUS,22
    So when ever i put the child id as 22 i should get the 14
    So when ever i put the child id as 21 i should get the 14
    So when ever i put the child id as 9 i should get the 1
    So when ever i put the child id as 15 i should get the 1
    So when ever i put the child id as 5 i should get the 1
    So when ever i put the child id as 3 i should get the null
    So when ever i put the child id as 14 i should get the 1.
    Please help me......
    There is one complex requirement in matrix format.
    Need P_ID , P_NAME , Count( child records)
    P_(nth), P_NAME(nth), Count(child record) nth times.
    Child is again the parent of some child.
    Report is needed for audit purpose.
    Message was edited by: Sandeep Sharma
    Sandeep Sharma

    SQL> CREATE TABLE SANDEEP(P_ID NUMBER,P_NAME VARCHAR2(100),C_ID NUMBER);
    Table created.
    SQL> INSERT INTO SANDEEP VALUES(null,'Computer',1);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(1,'KeyBoard',2);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(1,'Mouse',3);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(1,'Mother Board',4);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(3,'Scroll Mouse',5);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(3,'Optical Scroll Mouse',6);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(3,'Fibre Scroll Mouse',7);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(2,'Multimedia Key Board',8);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(2,'Cordless Key Board',10);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(2,'Normal Key Board',9);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(4,'586 Mother Board',13);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(4,'386 Mother Board',11);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(4,'486 Mother Board',12);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(4,'P1 Mother Board',14);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(4,'P2 Mother Board',15);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(4,'P3 Mother Board',16);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(4,'P4 Mother Board',17);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(14,'533 Mhtz P1 CPU',19);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(14,'433 Mhtz P1 CPU',18);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(19,'533 Mhtz P1 CPU With 100Mhtz BUS',20);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(19,'533 Mhtz P1 CPU With 133Mhtz BUS',21);
    1 row created.
    SQL> INSERT INTO SANDEEP VALUES(18,'433 Mhtz P1 CPU With 100Mhtz BUS',22);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> set null null
    SQL> SELECT P_ID
      2    FROM SANDEEP
      3     WHERE LEVEL = 2
      4     START WITH C_ID = &1
      5     CONNECT BY C_ID = PRIOR P_ID;
    Enter value for 1: 22
    old   4:    START WITH C_ID = &1
    new   4:    START WITH C_ID = 22
          P_ID
            14
    SQL> /
    Enter value for 1: 21
    old   4:    START WITH C_ID = &1
    new   4:    START WITH C_ID = 21
          P_ID
            14
    SQL> /
    Enter value for 1: 9
    old   4:    START WITH C_ID = &1
    new   4:    START WITH C_ID = 9
          P_ID
             1
    SQL> /
    Enter value for 1: 15
    old   4:    START WITH C_ID = &1
    new   4:    START WITH C_ID = 15
          P_ID
             1
    SQL> /
    Enter value for 1: 5
    old   4:    START WITH C_ID = &1
    new   4:    START WITH C_ID = 5
          P_ID
             1
    SQL> /
    Enter value for 1: 3
    old   4:    START WITH C_ID = &1
    new   4:    START WITH C_ID = 3
          P_ID
    null
    SQL> /
    Enter value for 1: 14
    old   4:    START WITH C_ID = &1
    new   4:    START WITH C_ID = 14
          P_ID
             1
    SQL> SY.

  • I need help with a SELECT query - help!

    Hello, I need help with a select statement.
    I have a table with 2 fields as shown below
    Name | Type
    John | 1
    John | 2
    John | 3
    Paul | 1
    Paul | 2
    Paul | 3
    Mark | 1
    Mark | 2
    I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
    Thanks,
    Ian

    Or, if the types are sequential from 1 upwards you could simply do:-
    SQL> create table t as
      2  select 'John' as name, 1 as type from dual union
      3  select 'John',2 from dual union
      4  select 'John',3 from dual union
      5  select 'Paul',1 from dual union
      6  select 'Paul',2 from dual union
      7  select 'Paul',3 from dual union
      8  select 'Paul',4 from dual union
      9  select 'Mark',1 from dual union
    10  select 'Mark',2 from dual;
    Table created.
    SQL> select name
      2  from t
      3  group by name
      4  having count(*) <= 2;
    NAME
    Mark
    SQL>Or another alternative if they aren't sequential:
    SQL> ed
    Wrote file afiedt.buf
      1  select name from (
      2    select name, max(type) t
      3    from t
      4    group by name
      5    )
      6* where t < 3
    SQL> /
    NAME
    Mark
    SQL>Message was edited by:
    blushadow

  • Need query help... Urgent Plz

    hi,
    i have the table like this.
    cityid ----- productcode
    1 ------ 100
    1 ------ 100
    2 ------ 101
    2 ------ 100
    2 ------ 102
    2 ------ 102
    2 ------ 102
    3 ------ 103
    3 ------ 104
    3 ------ 102
    i have 20 lacks records in the table.
    i want to retrive top 20 city based on the cityid count descending order,
    and top 1 product code of these cities based in the product count descending order.
    i need the query for this.
    Thanks,
    S.Ashokkumar.

    Hi,
    can try this,
    --not tested
    SELECT COUNT(*) , citiid, productcode
    FROM table1 t1
    having max(productcode) = (SELECT max(productcode) from table1 t2 where t1.citiid= t2.citiid)
    GROUP BY citiid, productcode
    order by citiid DESC
    May be this link will help.
    http://forums.oracle.com/forums/ann.jspa?annID=719
    thanks

  • Query help: query to return column that represents multiple rows

    I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
    I need a query to find all names that occur in both of two separate locations.
    For example,
    bob usa
    bob mexico
    dot mexico
    dot europe
    hal usa
    hal europe
    sal usa
    sal mexico
    The query in question, if given the locations usa and mexico, would return bob and sal.
    Thanks for any help or advice,
    -=beeky

    How about this?
    SELECT  NAME
    FROM    <LOCATIONS_TABLE>
    WHERE   LOCATION IN ('usa','mexico')
    GROUP BY NAME
    HAVING COUNT(DISTINCT LOCATION) >= 2Results:
    SQL> WITH person_locations AS
      2  (
      3          SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      4          SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      5          SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      6          SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      7          SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      8          SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      9          SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
    10          SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
    11  )
    12  SELECT  NAME
    13  FROM    person_locations
    14  WHERE   LOCATION IN ('USA','Mexico')
    15  GROUP BY NAME
    16  HAVING COUNT(DISTINCT LOCATION) >= 2
    17  /
    NAM
    bob
    salHTH!
    Edited by: Centinul on Oct 15, 2009 2:25 PM
    Added sample results.

  • Query Help-2

    Query Help:
    http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
    It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
    The above was my previous posting, which was not clear..so Iam restating my problem as follows....
    I have the following tables
    Customer(custID, Name, Address)
    Order(custID, OrderID, orderDate)
    CreditCard(custID, creditCard#, creditCardType)
    Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
    Order:
    100,A001,11/22/03
    100,A002,11/24/03
    100,A003,12/02/03
    CreditCard:
    100,42323232..., VISA
    100,5234234...., MASTER
    Now how can I get
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    data in minimum no. of records....
    I think I have made my query clear..
    now please help me guys...
    thanks so much for your help.

    You are right.
    But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
    Can you please help me with the query
    if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
    With the following fields in my query result,
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    from Customer, Order, CreditCard tables
    Thanks so much for your htlp

  • Query help to find missing rows

    Hi,
    Create tableA (
    columname varchar2;
    Insert into tableA ('a3');
    Insert into tableA ('dd');
    Select * from tablename where column in ( a3, b12,c34, dd ); -- 4 Values provided
    Need a query to return b12,c34 ie I have to find which records or not returning from a table for a given values.
    Please help
    Thanks
    Arvy
    Edited by: ARVY on Jun 19, 2012 11:10 AM
    Edited by: ARVY on Jun 19, 2012 11:16 AM

    ARVY wrote:
    I am using Oracle 9i versionFollowing is query that should be compatible on 9i.
    Please test it,since I am not able to do it due to unavailability of Oracle 9i with me.
    with data as
      select 'a,b,c,d' || ',' col from dual
    isolated_data as
      select trim(both ',' from (substr(col,
                  DECODE(level,
                          1, 1,
                          instr(col, ',', 1, level - 1) + 1
                  DECODE(level,
                          1, instr(col, ',', 1, level),
                          instr(col, ',', 1, level) - instr(col, ',', 1, level - 1)
                 ) ))col1
        from data
       connect by level <= length(col) - length(replace(col, ','))
    select a.col1
      from isolated_data a
    where a.col1 NOT IN (select col from test_Table);Regards,
    P.

  • Need MDX query to find something like date diff and Date Range for last 10 days

    Hi ,
    I need two Query .First Query for below;
    I have below data in table like.
    Cat      StartDate    EndDate     
    A    2000-01-01     2000-01-15   
    B    2000-01-02     2000-01-30    
    C    2000-01-01     2000-01-31    
    D    2000-02-01     2000-02-28    
    A    2000-01-10     2000-01-31    
    I need if Startdate and Date completes whole one month then set status =1 else  0 using MDX query.
    like this ;
    Cat      StartDate    EndDate       Status
    A    2000-01-01     2000-01-15    1
    B    2000-01-02     2000-01-30    0
    C    2000-01-01     2000-01-31    1
    D    2000-02-01     2000-02-28    1
    A    2000-01-10     2000-01-31    1
    In second query I need last 10 days from current days like;
    Now = 8/20/2014
    output will be ;
    8/20/2014
    8/19/2014
    8/18/2014
    8/17/2014
    8/16/2014
    8/15/2014
    8/14/2014
    8/13/2014
    8/12/2014
    8/11/2014
    8/10/2014
    Please help me .
    Thanks

    Hi Prajapati,
    In your scenario, you can use Properties and Datediff function to achieve your requirement. Since not know the structure of your cube, we cannot give you the esact query.
     I have tested it on the AdventureWorks cube, the query below is for you reference.
    WITH MEMBER [Measures].[StartDate]
    AS
    [Employee].[Employee Department].CURRENTMEMBER.PROPERTIES('Start Date')
    MEMBER [Measures].[WorkYear]
    AS
    DATEDIFF('yyyy',[Measures].[StartDate],NOW())
    MEMBER [Measures].[Status]
    AS
    IIF(DATEDIFF('yyyy',[Measures].[StartDate],NOW())>10,1,0)
    SELECT {[Measures].[StartDate],[Measures].[WorkYear],[Measures].[Status]} ON 0,
    [Employee].[Employee Department].[Employee].MEMBERS ON 1
    FROM [Adventure Works]
    Results
    Reference
    http://msdn.microsoft.com/en-us/library/ms144821.aspx
    Regards,
    Charlie Liao
    TechNet Community Support

  • SQL Query Help - Is this possible or impossible????

    Hi guys,
    I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
    For example,
    I have 2 tables
    The first table is:
    1) COMPANY create table company (manufacturer varchar2(25),
                                                          date_established date,
                                                          location varchar2(25) );My sample test date is:
    insert into company values ('Ford', 1902, 'USA');
    insert into company values ('BMW', 1910, 'Germany');
    insert into company values ('Tata', 1922, 'India');The second table is:
    2) MODELS create table models (manufacturer varchar(25),
                                                 model varchar2(25),
                                                 price number(10),
                                                 year date,
                                                 current_production_status varchar2(1) ) ;My sample test data is:
    insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
    insert into models values ('Ford', 'Galaxy', 12000,   2008, 0);
    insert into models values ('Ford', 'Escort', 10000, 1992, 1);
    insert into models values ('BMW', '318', 17500, 2010, 0);
    insert into models values ('BMW', '535d', 32000,   2006, 0);
    insert into models values ('BMW', 'Z4', 10000, 1992, 0);
    insert into models values ('Tata', 'Safari', 4000, 1999, 0);
    insert into models values ('Tata', 'Sumo', 5500,   1996, 1);
    insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer IN ('Ford', 'BMW', 'Tata')
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCWhat I want the query to output is this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               Sumo               5500               1998          1If current_production_status is 1 it means this particular model has been discontinued
    If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
    The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
    So the query should output the one row where current_production_status is 1 for each manufacturer.
    If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
    My query as it is above will output all the records where current status is 1 or 0 like this
    com.manufacturer        com.date_established          com.location          mod.model          mod.price          mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    Tata               1922                    India               Sumo               5500               1998          1
    Ford               1902                    USA               -               -               -          0                    
    Ford               1902                    USA               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               -               -               -          0
    Tata               1922                    India               -               -               -          0However this is not what I want.
    Any ideas how I can achieve the result I need?
    Thanks!
    P.S. Database version is '10.2.0.1.0'

    Hi Vishnu,
    Karthiks query helped...
    But this is the problem I am facing...
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer = 'Ford'
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCThe value of:
    and com.manufacturer = 'Ford'will be dependent on front end user input....
    When I run the query above I get all the rows where current_production_status is either 1 or 0.
    I only require the rows where current_production_status is 1.
    So if I amend it to look like this:
         and mod.current_production_status = 1This works....
    BUT if a user now passes in more than one manufacturer EG:
    and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
    So like this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
    Thanks you so much!
    This is really driving me insane :-(

  • In need of desparate help (newbie)

    so my plan is simple. from the execute query i bring back multiple resultsets, which i then populate into a vector. then this vector must be redirected to a JSP to iterate through a loop and display the results.
    here is my following code:
    test.java
    Vector vRecords = new Vector();
    while(rs.next()){
    temp.setMarkerId(rs.getInt("markId"));
    temp.setFirstName(rs.getString("markFName"));
    temp.setLastName(rs.getString("markLName"));
    temp.setAddress(rs.getString("streetAddress"));
    temp.setCity(rs.getString("city"));
    temp.setProvince(rs.getString("province"));
    vRecords.add(temp);
    request.setAttribute("markerList",vRecords);
    //response.sendRedirect("../results.html");
    RequestDispatcher disp = request.getRequestDispatcher("../../results.jsp");
    disp.forward( request, response );
    dbConnection.close();This is my error message:
    Mar 13, 2005 11:12:48 PM
    org.apache.catalina.loader.WebappClassLoader validateJarFile
    INFO: validateJarFile(C:\jakarta-tomcat-5.5.8\webapps\ROOT\WEB-INF\lib\servlet.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
    java.lang.NullPointerException
    please and thanks. i am in need of desparate help.
    johnny.

    The problem might be due to some other servlet JAR which is already loaded and using a different version of servlet specifications. Check your Classpath for other JARs present.
    $Carol

  • I need a query

    Hi
    I've a table with 3(THREE)columns like the following structure:
    desc acc
    Name Null? Type
    MCODE NOT NULL NUMBER(2)
    TYPE CHAR(1)
    BALANCE NUMBER(14,2)
    Select * from acc
    MCODE TYPE BALANCE
    10 I 0
    11 L 0
    12 E 0
    12 L 0
    13 L 0
    14 L 0
    15 L 0
    16 E 154689718
    16 I 11244750
    16 L -11232000
    16 R 234178693
    17 L 0
    18 L 0
    13 rows selected.
    Pls Look at the above query that each ID(MCODE) may 4(four) TYPE ( E,I,L,R) and no more than these But each ID(MCODE) may have TYPE : 1 ( E or I or L or R) ,2 ( E,I or L,R or E,L or I,R ) ,3 (...., ...., ...,or ...,...,...).
    Now I need a query That BALANCE will be group by each MCODE base of clmn TYPE which result will be as follows:
    MCODE BALANCE
    10 ((I) + (R)) - ((E) + abs(L)) Where I= 11244750, R= 234178693
    11 ((I) + (R)) - ((E) + abs(L)) E= 154689718, L= -11232000
    12 ((I) + (R)) - ((E) + abs(L))
    13 ((I) + (R)) - ((E) + abs(L))
    14 ((I) + (R)) - ((E) + abs(L))
    15 ((I) + (R)) - ((E) + abs(L))
    16 ((I) + (R)) - ((E) + abs(L))
    17 ((I) + (R)) - ((E) + abs(L))
    18 ((I) + (R)) - ((E) + abs(L))
    how can it be done in a single oracle query can anyone help me
    Regards
    Alamgir Hossain
    Message was edited by:
    user628107
    Message was edited by:
    user628107
    Message was edited by:
    user628107

    Dear Mr. damorgan
    I respect your previous message. what you mean by honest attempt I don't know. As far we know all are respectable IT professionals in this forum. So we couldn’t expect like that answer from you.
    If you think, that is school work Pls prove yourself. I again post the problem with script specially for your kind attention.
    how can it be done in a single oracle query
    Create table acc(     
    MCODE     NUMBER(2) NOT NULL
    ,TYPE     CHAR(1)
    ,BALANCE     NUMBER(14,2)
    Insert into acc values(11,'L',0);
    Insert into acc values(12,'E',76000);
    Insert into acc values(12,'L',-4500);
    Insert into acc values(13,'L',0);
    Insert into acc values(14,'L',-5000);
    Insert into acc values(15,'L',0);
    Insert into acc values(16,'I',11244750);
    Insert into acc values(16,'E',154689718);
    Insert into acc values(16,'L',-11232000);
    Insert into acc values(16,'R',234178693);
    Insert into acc values(17,'L',0);
    Insert into acc values(18,'L',0);
    Select * from acc
    MCODE TYPE BALANCE
    11 L 0
    12 E 76000
    12 L -4500
    13 L 0
    14 L -5000
    15 L 0
    16 I 11244750
    16 E 154689718
    16 L -11232000
    16 R 234178693
    17 L 0
    18 L 0
    Pls Look at the above query that each ID(MCODE) may 4(four) TYPE ( E,I,L,R) and no more than these But each ID(MCODE) may have atleast TYPE : 1 ( E or I or L or R) OR 2 ( E,I or L,R or E,L or I,R ) OR 3 (...., ...., ...,or ...,...,...).
    Now I need a query That BALANCE will be group by each MCODE base of clmn TYPE which query result will be as follows :
    ( balance = ((I) + (R)) - ((E) + abs(L)))
    Where I= 11244750, R= 234178693
    E= 154689718, L= -11232000
    MCODE BALANCE
    10           0
    11          0
    12          -80500
    13          0
    14          -5000
    15          0      
    16          79501725
    17          0
    18      0
    how can it be done in a single oracle query

  • Need a Query to update....below are requirements

    Hi,
    I need a query to update table xx_cc_audit. below are requirements.
    In xx_cc_audit I have more than 1000 rows. In this table Column - contract_number is inserted as null for some rows.
    I need a query to update this xx_cc_audit table which will replace null contract numbers with correct ones.
    In table xx_cc_audit I have column - instance_id which is not null and not unique.(duplicate instance id's can be there).
    With this instance_id i can get the contract_number from other table okc_k_headers_b .
    I need a query to update xx_cc_audit table.
    Presently what I'm doing :
    Select XS.instance_id
    FROM cs_incidents_all_b CS,xx_cc_audit XS
    where XS.contract_number is null
    AND XS.SR_NUMBER = CS.incident_number
    AND XS.ACTIVITY_TYPE = 'TROUBLESHOOTING';
    Note : The above query can give duplicate instance_id.
    Say, above query results in 100rows.
    I will copy any 1 instance_id in a paper and then pass it to below query.
    SELECT contract_number
    FROM okc_k_headers_b
    WHERE id = (SELECT MAX(dnz_chr_id)
    FROM okc_k_items
    WHERE object1_id1 = TO_CHAR(144849056) --instance_id
    AND jtot_object1_code = 'OKX_CUSTPROD'
    AND object1_id2 = '#'
    AND chr_id IS NOT NULL);
    I'll get contract_number.
    then i'll update xx_cc_audit table as below.
    update      xx_cc_audit set contract_number = 1223464789 -- which i got as a result of above query
    where contract_number is null
    and instance_id = 144849056     --this i copied from paper, as mentioned above     ;
    this will update my table.
    I have more than 1000rows, so i need a query which will update 1000rows in 1 shot.
    Please help me.
    Thanks!...
    Edited by: Kiran Sanga on Jul 20, 2009 2:15 AM

    OK, so that means a maximum of 10 distinct IDs in okc_k_headers_b can be matched with xx_cc_audit xca.
    That's a data issue for yourself that you'll need to work out, i.e, are you being too restrictive in any of the subqueries, particularly this one:
    WHERE id = (
        SELECT MAX(dnz_chr_id)
          FROM okc_k_items
        WHERE object1_id1 IN (
          Select XS.instance_id
          FROM cs_incidents_all_b CS,xx_cc_audit XS
          where XS.contract_number is null
            AND XS.SR_NUMBER = CS.incident_number
            AND XS.ACTIVITY_TYPE = 'TROUBLESHOOTING')
      AND jtot_object1_code = 'OKX_CUSTPROD'
      AND object1_id2 = '#'
      AND chr_id IS NOT NULL)Edited by: SeánMacGC on Jul 20, 2009 3:37 AM
    And here is a slight different version of the update that should perform a little better:
    update xx_cc_audit xca set contract_number = (
      SELECT contract_number
        FROM okc_k_headers_b okhb
    WHERE id IN (
        SELECT dnz_chr_id
          FROM okc_k_items
        WHERE object1_id1 IN (
          Select XS.instance_id
          FROM cs_incidents_all_b CS,xx_cc_audit XS
          where XS.contract_number is null
            AND XS.SR_NUMBER = CS.incident_number
            AND XS.ACTIVITY_TYPE = 'TROUBLESHOOTING')
      AND jtot_object1_code = 'OKX_CUSTPROD'
      AND object1_id2 = '#'
      AND chr_id IS NOT NULL)
      AND xca.instance_id = okhb.object1_id1
    where contract_number is null;

Maybe you are looking for