SQL query between two table

Hi all
Following the script nicely:
CREATE TABLE ACCOUNT_LOOCKUP
(
  SERIAL_ID     NUMBER,
  ACCOUNT_ID    NUMBER,
  ACCOUNT_RATE  NUMBER,
  ACCOUNT_MAX   NUMBER
)

ALTER TABLE ACCOUNT_LOOCKUP ADD (
  CONSTRAINT PK_ACCOUNT_LOOCKUP
 PRIMARY KEY
 (SERIAL_ID, ACCOUNT_ID));



Insert into ACCOUNT_LOOCKUP
   (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
 Values
   (1, 1, 10, 200);
Insert into ACCOUNT_LOOCKUP
   (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
 Values
   (2, 1, 12, 150);
Insert into ACCOUNT_LOOCKUP
   (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
 Values
   (3, 1, 8, 400);
Insert into ACCOUNT_LOOCKUP
   (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
 Values
   (1, 2, 7, 100);
Insert into ACCOUNT_LOOCKUP
   (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
 Values
   (2, 2, 5, 200);
COMMIT;


SELECT * FROM ACCOUNT_LOOCKUP

 SERIAL_ID ACCOUNT_ID ACCOUNT_RATE ACCOUNT_MAX
---------- ---------- ------------ -----------
         1          1           10         200
         2          1           12         150
         3          1            8         400
         1          2            7         100
         2          2            5         200
         
         
CREATE TABLE ACCOUNT_AMOUNT(
ACCOUNT_ID NUMBER(10),
ACCOUNT_AMNT NUMBER(10))


Insert into ACCOUNT_AMOUNT
   (ACCOUNT_ID, ACCOUNT_AMNT)
 Values
   (1, 9);
Insert into ACCOUNT_AMOUNT
   (ACCOUNT_ID, ACCOUNT_AMNT)
 Values
   (1, 35);
COMMIT;
 
SELECT * FROM ACCOUNT_AMOUNT
 
ACCOUNT_ID ACCOUNT_AMNT
---------- ---------------
         1               9
         1              35
       
I want by select query calculte ACCOUNT_TOTAL every ACCOUNT_ID exists in table ACCOUNT_AMOUNT as below ,

1. every ACCOUNT_ID have SERIAL_ID and ACCOUNT_RATE and ACCOUNT_MAX in table ACCOUNT_LOOCKUP,
2. to calculte ACCOUNT_TOTAL every ACCOUNT_ID : 
   
   - order ascending SERIAL_ID exists in table ACCOUNT_LOOCKUP to every ACCOUNT_ID exists in table ACCOUNT_AMOUNT ,
   - make sum ACCOUNT_AMNT every ACCOUNT_ID in table ACCOUNT_AMOUNT,
   - then, copmare result (sum ACCOUNT_AMNT) with first record after ascending SERIAL_ID,
   - product (sum ACCOUNT_AMNT) * ACCOUNT_RATE  result as ACCOUNT_TOTAL,(in ex: sum ACCOUNT_AMNT  = 44   ) ,
   - if ACCOUNT_TOTAL > ACCOUNT_MAX then 
         * ACCOUNT_TOTAL = ACCOUNT_MAX for first record(in ex SERIAL_ID = 1 ) ,
         * Goto the second record by ascending (in ex SERIAL_ID = 2 ) ,
           make ( ACCOUNT_TOTAL / ACCOUNT_RATE ) for first record ,
           ( 200 / 10 ) result 20 >>
           
         * calculate Remainder ACCOUNT_AMNT =  the sum ACCOUNT_AMNT 44 - 20 = 24 
         
            *Goto the second record by ascending (in ex SERIAL_ID = 2 ) ,   
               Remainder ACCOUNT_AMNT 24 * (12) ACCOUNT_RATE for second record = 288 as ACCOUNT_TOTAL 
               -if ACCOUNT_TOTAL > ACCOUNT_MAX then 
               * ACCOUNT_TOTAL = ACCOUNT_MAX for second record(in ex SERIAL_ID = 2 ) ,
                  * Goto the third record by ascending (in ex SERIAL_ID = 3 ) ,
                  make ( ACCOUNT_TOTAL / ACCOUNT_RATE ) for second record ,
                   ( 150 / 12 ) result 12.5
               
                    * calculate Remainder ACCOUNT_AMNT =  the sum ACCOUNT_AMNT 24 - 12.5 = 11.5 
                    Remainder ACCOUNT_AMNT 9.5 * (12) ACCOUNT_RATE for third record = 92 result as ACCOUNT_TOTAL 
                    if result <= ACCOUNT_MAX then 
                        ACCOUNT_TOTAL = 92 
except result
------------

SERIAL_ID ACCOUNT_ID ACCOUNT_RATE ACCOUNT_MAX   ACCOUNT_TOTAL          ** explain ** 
---------- ---------- ------------ -----------  -------------  *****  sum ACCOUNT_AMNT  = 44 for ACCOUNT_ID = 1from table ACCOUNT_AMOUNT ******
         1          1           10         200          200  >> (44 * 10 ) = 440 >>  200 /10 rate = 20 >> 44 - 20 = 24 Remainder ACCOUNT_AMNT
         2          1           12         150          150  >> (22 * 12 ) = 288 >>  150 /12 rate = 12.5 >> 24 - 12.5 = 11.5 Remainder ACCOUNT_AMNT
         3          1            8         400           92  >> (11.5 * 8)  = 92  And so on ....
    
another insert 
Insert into ACCOUNT_AMOUNT
   (ACCOUNT_ID, ACCOUNT_AMNT)
 Values
   (2, 10);         
   
   
SELECT * FROM ACCOUNT_AMOUNT
 
ACCOUNT_ID ACCOUNT_AMNT
---------- ---------------
         1               9
         1              35
         2              10    
         

except result
------------
  

SERIAL_ID ACCOUNT_ID ACCOUNT_RATE ACCOUNT_MAX   ACCOUNT_TOTAL          ** explain ** 
---------- ---------- ------------ -----------  -------------  *****  sum ACCOUNT_AMNT  = 10 for ACCOUNT_ID = 2 from table ACCOUNT_AMOUNT ******
         1          1           10         200          200  
         2          1           12         150          150  
         3          1            8         400           92           
         1          2            7         100           70    10 * 7 = 70 
Help me please
Thanks in advance

Hello

Please do not post duplicate questions.

calculate the value of the query help

David

Tags: Database

Similar Questions

  • Use a where clause clause if there is a relationship between two tables

    Is it possible to use a where clause clause if there is a relationship between two tables.
    I have a relationship between two tables:
    And a.customer = b.customer (+)

    If b.customer exists in a.customer I would add this in where clause
    And b.info = 'X '.
    But how?

    It's the outer joins by chance?

    If so, why not just:

    and  b.customer(+) = a.customer
    and  b.info(+) = 'X'
    

    BTW, I put the two "b" on the left column to make it easier to read. Some people mix that makes me crazy, but makes no difference to the query.

  • I got a prob while creating a link/link between two tables in a jdeveloper11g

    Hi guys...

    I got a prob while creating a link/link between two tables in a jdeveloper11g, help me.

    I use two table employee, Department.

    Unfortunately there is no primary key and foreign key in these tables.now i updated on those of table structure.

    I want to create a form like it should be a link between the Department data, i.e. data and employee while the Department is changed then only present corresponding employees in this block...

    Table structure as follows

    Employee:

    -------------------

    employe_id,

    name,

    Department,

    GR,

    Date of birth

    Department of justice

    Department:

    --------------------

    department_id,

    department_name;

    Note: in the employee department table is the same as in the department table department_id...

    So, you want to build master / detail between Department & sub_departments?

    In the same way, create a new, yet another link between departments & sub_departments, so that the connection is:

    Department.Department_Id = sub_departments.department_id

  • I need to implement Drag N Drop between two tables that saves the two records

    I need to implement Drag N Drop between two tables that saves the two records on a third page, using drag 'n drop.

    Check out this video http://baigsorcl.blogspot.com/2011/01/drag-and-drop-collection-in-oracle-adf.html

  • two relationships between two tables

    Hi all

    I created a cube in my db (using OWB) of two relationships to my time dimension. A relationship shows the start time of a process, that the other represents the date of termination or end.

    example of the cube:

    Fact1
    Fact2
    Dim_Time1
    Dim_Time2

    where Dim_time1 and Dim_Time2 link to the same dimension.

    Unfortunately I have trouble this manually import in obiee administrator. I imported the fact table and the dimension of the physical layer table. Can I move to the business layer and create the two joins between two tables. But the overall consistency check up a mistake, I shouldn't have two relationships between two tables and remove a foreign key.

    What I am doing wrong?

    Kind regards

    Knut

    Knut,

    In your example, you should have a time dimension in the phyiscal layer and alias of this 2 x, for Dim_time1 and for Dim_time2, in this way aliases are separate tables as the BI server point of view and you define releations separate on the same table, you can define specific to each alias dim relevant time joins.

    In this way, you will have two time decreases intensity in MDB layer also, has 'Dim-Start Time' and a ' Sun - term time "or similar.

    Hope this helps,
    Alastair

  • How to remove the extra space between two Table HTML

    Hello

    I wrote a code for printing costs. But there is more space between two Table Html, how I can remove it.

    Please run that Code

    Start

    HTP.p (')
    < html >
    (< body > ');

    HTP.p (')
    < TABLE align = "left" width = "500" cellspacing = "0" cellpadding = "0" border = "1" >
    < tr > < td align = 'right' white-space: nowrap; > Ph-2201751 < table >
    < td > < table >
    < /tr >
    < tr > < td align = "center" white-space: nowrap; > < B > < table > < /B > SATYAM MODERN PUBLIC SCHOOL
    < td > < table >
    < /tr >
    < b >
    < td align = "center" white-space: nowrap; > < i > < H3 > (AFFILIATED to THE CBSC, NEW DELHI CODE No. 53544) < / H3 > < /I > < table >
    < td > < table >
    < /tr >
    < tr > < td align = "center" white-space: nowrap; > new colony Braham, - 131001 (h) < table >
    < td > < table >
    < /tr >
    < tr > < td align = "center" white-space: nowrap; > RECEPTION COSTS < table >
    < td > < table >
    < /tr >
    < /table >
    < TABLE width = "500" cellspacing = "0" cellpadding = "0" border = "1" >
    < b >
    < td width = "100" white-space: nowrap; > receipt no.: < table >
    < td width = "100" white-space: nowrap; > Date received: < table >
    < /tr >
    < b >
    < td width = "100" white-space: nowrap; > name: < table >
    < td width = "100" white-space: nowrap; > father name: < table >
    < /tr >
    < b >
    < td width = "100" white-space: nowrap; > class & s: < table >
    < td width = "100" white-space: nowrap; > A/C No. : < table >
    < /tr >
    < b >
    < td width = "100" white-space: nowrap; > from: < table >
    < td width = "100" white-space: nowrap; > to: < table >
    < /tr >

    (< /table > ');
    HTP.p (')
    < / body >
    (< / html > ');
    end;


    Thank you

    Ed

    Hello

    HTML is valid, that your code print?

    
    

    Wouldn't be as below?

    
    

    BR, Jari

    Published by: jarola on December 18, 2009 15:22
    I test your code
    http://Apex.Oracle.com/pls/OTN/f?p=40323:25
    I can't see any extra space between the tables

  • The most elegant way to get the difference between two tables - not least!

    Hello


    Simplified example of what I'm trying to achieve - I have two tables ORIGINAL and REVISED.


    My aim is to compare the two, such as; -


    When there is data in the two tables I get the difference between the Budget column, and if there is no difference, so I don't want no lines.

    When data exists in the ORIGINAL, but not in review, I want to the inverse of the current value of the Budget column.

    Where the data exist in REVISED I want the REVISED value.

    I can see how I can do this, see below, but is there a more elegant solution?




    Data for the ORIGINAL table
    select '801040' entity, '2186' expense_type, 234000 budget
    from dual
    union all
    select '801040' entity, '3001' expense_type, 1000 budget
    from dual
    union all
    select '801040' entity, 'P132' expense_type, 34000 budget
    from dual
    union all
    select '801040' entity, 'P135' expense_type, 43000 budget
    from dual
    Data for the REVISED table
    select '801040' entity, '2186' expense_type, 235000 budget
    from dual
    union all
    select '801040' entity, 'P132' expense_type, 34000 budget
    from dual
    union all
    select '801040' entity, 'P139' expense_type, 56000 budget
    from dual
    Desired output



    ENTITY EXPENSE_TYPE DIFFERENCE
    ------ ------------ ----------
    801040 2186 1000
    801040 3001-1000
    801040 P135-43000
    801040 P139 56000

    5 selected lines.



    Code current to achieve this, is there a better way?
    select original.entity
    ,      original.expense_type
    ,       (nvl(revised.budget,0) - original.budget) as difference
    from   original
    ,      revised
    where  original.entity = revised.entity(+)
    and    original.expense_type = revised.expense_type(+)
    and   (nvl(revised.budget,0) - original.budget) != 0
    union all
    select  revised.entity
    ,       revised.expense_type
    ,       revised.budget as difference
    from   revised
    where  not exists
    (select 'x'
    from   original
    where  original.entity = revised.entity
    and    original.expense_type = revised.expense_type)
    and    revised.budget != 0
    Thanks a lot for your comments,.


    Robert.

    Published by: Robert Angel on January 17, 2012 03:31 to change is not equal to! = - Thanks for the heads up
    SQL> with original
      2  as
      3  (
      4    select '801040' entity, '2186' expense_type, 234000 budget
      5    from dual
      6    union all
      7    select '801040' entity, '3001' expense_type, 1000 budget
      8    from dual
      9    union all
     10    select '801040' entity, 'P132' expense_type, 34000 budget
     11    from dual
     12    union all
     13    select '801040' entity, 'P135' expense_type, 43000 budget
     14    from dual
     15  )
     16  , revised
     17  as
     18  (
     19    select '801040' entity, '2186' expense_type, 235000 budget
     20    from dual
     21    union all
     22    select '801040' entity, 'P132' expense_type, 34000 budget
     23    from dual
     24    union all
     25    select '801040' entity, 'P139' expense_type, 56000 budget
     26    from dual
     27  )
     28  select *
     29    from (
     30          select nvl(o.entity, r.entity) entity,
     31                 nvl(o.expense_type, r.expense_type) expense_type,
     32                 nvl(r.budget,0) - nvl(o.budget,0) budget
     33            from original o
     34            full join revised r
     35              on o.entity = r.entity
     36             and o.expense_type = r.expense_type
     37         )
     38   where budget <> 0
     39  /
    
    ENTITY EXPE     BUDGET
    ------ ---- ----------
    801040 2186       1000
    801040 P135     -43000
    801040 3001      -1000
    801040 P139      56000
    
    SQL>
    
  • getting data between two tables

    Hi everyone, I need help with a query that seems simple, but I can't understand. consider the following data.

    with data as (

    s élire 802 cd from dual union all

    select 803 cd from dual union all

    select 804 cd from dual

    data2 as

    ( select 804 cd from dual )


    I want to join the two tables so that the result will be as follows:

    in the above data, we can see that 804 is common in both tables.  in this case, the output should be 804.

    Similarly, if 2 data include the following:

    data2 as

    ( select 804 cd from dual union all

    Select 803 cd from dual

    )


    the output is then 803 804.



    Now consider the following data

    with data as (

    s élire 802 cd from dual union all

    select 803 cd from dual union all

    select 804 cd from dual

    )

    take data2 table is empty


    I want to join the two tables, and in this case, the output should be 802,803,804.  data2 table is empty, then the default behavior is to get all the data in the data table. Since there is no line that corresponds to rows in the data table,

    the default behavior is to display output all data in the data table.  in this case 802,803,804

    can someone write a query for this?

    Hello

    elmasduro wrote:

    Hi Frank, thanks for the request.  These are very good questions. Here are the answers

    What happens if data2 rows, but none of them match data CD?

    It won't happen because the integrity of the data.

    ...

    I see it; a data line 2 will be in the data.  You have a FOREIGN KEY constraint, or something similar, so if cd = 804 exists in database2, then it must also exist in the data.

    What happens if the data is empty and data2 is not?

    If data is empty and data2 is not, then the data2 data should be released.

    for example

    with the data as)

    data table is empty

    data2 as

    (select cd 804 Union double all the)

    Select cd 805 double

    )

    When you join data and data2 account with the above data, then the output should be 804 805.  data2 data should be the display if the data table is empty. ...

    Doesn't that contradict what you said earlier?  Previously, it seemed to say that each row of data2 will be in the data, but now you give an example where all data2 lines are not in the data.

    If the first is true, then the solution in response #2 should work.

    If the latter is true, you can change the query like this:

    WITH got_r_num AS

    (

    SELECT NVL (d.cd, d2.cd) AS cd

    DENSE_RANK () (ORDER IN CASE

    WHEN d.cd IS NOT NULL

    AND d2.cd IS NOT NULL

    THEN "A".

    WHEN d.cd IS NOT NULL

    THEN 'B '.

    ANOTHER 'C '.

    END

    ) AS r_num

    DATA d

    FULL OUTER JOIN data2 d2 ON d.cd = d2.cd

    )

    SELECT cd

    OF got_r_num

    WHERE r_num = 1

    ORDER BY cd

    ;

  • Comparison between two tables

    Hello

    I have two tables USERS and LISTS:

    And I want that there is a comparison between these two tables executed when user table USERS connect to the application.

    They must compare the columns between the SEXES and AGE and if some users have the same attributes in its ranks as in a line in the table LISTS (here is unique each line) so that the user gets in his line in the column 'LIST_ID' the ID of the line with which attributes between GENDER and AGE.

    Example:

    USERS TABLE: exampleuser | Boby | McGrahem | Male | 18. -------

    LISTS OF TABLE: 28 | examplelist | Male | 18

    Once the Login of the user Boby gets in its ranks the ID = 28 because the SEX and AGE corresponds to the row of table LIST:

    Result:

    USERS TABLE: exampleuser | Boby | McGrahem | Male | 18. 28

    
    CREATE TABLE  "USERS" 
       (    "USERNAME" VARCHAR2(15) NOT NULL ENABLE, 
            "FORRNAME" VARCHAR2(15) NOT NULL ENABLE,                  
            "SURNAME" VARCHAR2(15) NOT NULL ENABLE, 
            "GENDER" VARCHAR2(10) NOT NULL ENABLE,   
            "AGE" NUMBER, 
            "LIST_ID" NUMBER, 
             CONSTRAINT " USERS_PK" PRIMARY KEY ("USERNAME")
      USING INDEX  ENABLE
    
    

    CREATE TABLE  "LISTS" 
       (    " LIST_ID" NUMBER NOT NULL ENABLE, 
            " LISTNAME" VARCHAR2(50) NOT NULL ENABLE, 
            "GENDER" VARCHAR2(10) NOT NULL ENABLE, 
            "AGE" VARCHAR2(3) NOT NULL ENABLE,  
             CONSTRAINT " LISTS_PK" PRIMARY KEY ("LIST_ID")
      USING INDEX  ENABLE
       
    

    I need help for coding this, if someone be so good.

    This is my essay:


    DECLARE  
        v_listid varchar2(100);   
        BEGIN  
          
        SELECT  LIST_ID into v_listgid
         FROM LISTS
         WHERE GENDER = (SELECT GENDER
                              FROM USERS 
                            WHERE UPPER(TRIM(USERNAME)) = UPPER(TRIM(:APP_USER)))
         AND AGE = (SELECT AGE
                              FROM USERS  
                            WHERE UPPER(TRIM(USERNAME)) = UPPER(TRIM(:APP_USER)));
    
         UPDATE USERS   
        SET LIST_ID =  v_listid   WHERE UPPER(TRIM(USERNAME)) = UPPER(TRIM(:APP_USER));  
      
        END;
    

    I'd like to REALLY shy away using the USER name as the primary key, because the fact that users can create duplicate user names... YOU should NEVER base a PK on the entry of user, the better to let the database create and maintain this element of date...

    FIX:

    UPDATE to users U

    SET List_Id = (SELECT List_Id OF lists L WHERE L.Gender = U.Gender and L.SOMENUMBER = U.SOMENUMBER) AND

    Upper (U.UserName) = UPPER(:APP_USER);

    Don't really want to cut the strings, Oracle which will do since they are of type varchar2 columns...

    Thank you

    Tony Miller
    Software LuvMuffin
    Ruckersville, WILL

  • Query combining two tables

    I have the following two tables:

    Asset_Issued

    Asset_Type_IDAssigned to
    1RAM
    2RAM
    3RAM
    4RAM
    5RAM
    1Riadh
    3Riadh
    5Riadh
    1Rajesh
    3Rajesh
    2Rajesh

    Asset_Type

    Asset_Type_IDAsset_Name
    1Laptop
    2Desktop
    3Mouse
    4Keyboard
    5Monitor

    Can someone help me with the query that will give the following result.

    Asset_Issued_Count

    Asset_NameCounty
    Laptop3
    Desktop2
    Mouse3
    Keyboard1
    Monitor1

    Really? It's really basic things.

    Select at.asset_name, count (*)

    of asset_type to

    Join asset_issued HERE on (ai.asset_type_id = at.asset_type_id)

    At.asset_name group;

  • recursive query with two tables

    Hello

    Im having problems of recursive query construction and add to select the list to see the result in hierarchical mode, so I want to your advice.

    I have two tables:
    TABLE: t1 
    c_id       parent_id      c_level
    1              -                 1
    2              1                 2
    3              1                 2
    4              -                 1
    5              4                 2
    6              5                 3
    
    TABLE: t2 
    c_id         c_name
    1               name1
    2               name2
    3               name3
    4               name4
    5               name5
    6               name6
    And I want to see the result like this:

    -Name1
    -name2
    -Name3
    -Name4
    -Name5
    -name6

    Could you please help me with this?
    Or maybe can you provide good links where I can find solution how to SELECT LIST looks like the hierarchical tree?

    Here is my test scenario:

    CREATE TABLE t1(
      c_id      NUMBER,
      parent_id NUMBER,
      c_level   NUMBER);
    
    CREATE TABLE t2(
      c_id   NUMBER,
      c_name VARCHAR2(10));
    
    INSERT INTO t1 VALUEs(1,NULL,1);
    INSERT INTO t1 VALUEs(2,1,   2);
    INSERT INTO t1 VALUEs(3,1,   2);
    INSERT INTO t1 VALUEs(4,NULL,1);
    INSERT INTO t1 VALUEs(5,4,   2);
    INSERT INTO t1 VALUEs(6,5,   3);
    
    INSERT INTO t2 VALUEs(1,'name1');
    INSERT INTO t2 VALUEs(2,'name2');
    INSERT INTO t2 VALUEs(3,'name3');
    INSERT INTO t2 VALUEs(4,'name4');
    INSERT INTO t2 VALUEs(5,'name5');
    INSERT INTO t2 VALUEs(6,'name6');
    
    SELECT LPAD('-',2 * a.c_level,'-') || b.c_name the_tree
      FROM t1 a,
           t2 b
     WHERE b.c_id = a.c_id
    CONNECT BY a.parent_id = PRIOR a.c_id
     START WITH a.parent_id IS NULL;
    

    and the result:

    THE_TREE
    ----------
    --name1
    ----name2
    ----name3
    --name4
    ----name5
    ------name6
    

    I took the example you gave then perhaps your largest data set has the flaw?

    Published by: SunDogCa on August 13, 2010 14:19

  • Difference between two tables (ORA-01722)

    I am trying to get the difference of two tables on two databases.

    Walker I run the script below, it gives me a result that is not accurate.
    Select name, creation_time of v$datafile@REMOTE_database.com
    2 LESS THAN
    3 select name, creation_time from v$ datafile;

    I get 14 ranks of foregoing.
    However, when I run this script, I get an accurate count of the difference. How can I list the exact number instead of only to count the difference? Want lists all five name missing on table 2.
    SQL > SELECT a.cnt - b.cnt
    > count 2 (name) select cnt (of v$datafile@REMOTE_database.com) a, b
    3 (select count (name) NTC v$ datafile);

    A.CNT - B. CNT
    -----------
    5
    edited by: Albert Zaza on July 19, 2010 11:19

    have you tried:

    select trim(upper(name)) from v$datafile@REMOTE_database.com
     MINUS
     select trim(upper(name)) from v$datafile;
    
  • SIMPLE SQL QUERY in a table IF statement but...

    Hello everyone

    I have a table and wants to interpret the medium to make comparisons between cells of different lines, say 4 and 6 colum and so for all lines

    the comparison may be just a division, but the problem is when I have a here X 0 / 0

    So I need to tell the application to check first if there is a 0 to ignore this and continue on the table for the following ranks

    I received what has worked in sql developer and also in the script, but the wizzard when I was going to launch the report in the tenth it came with an error below

    Select company, zip code.
    case
    When count (staff)! = 0 here end sum (Boss/staff)
    assessment
    Group of company, zip code


    1 error has occurred
    Query column #3 (CASEWHENCOUNT (STAFF)! = 0THENSUM(ADDICTS/STAFF) END) is not valid, use column aliases


    I don't know where to put, I tried in many places and it works ever, not to mention that I don't know if the query must be formatted differently to avoid the error...


    Thank you very much

    Alvaro

    Hi Alvaro,

    Generally, you wouldn't need one alias, unless it is part of something else, for example a create view, statement.
    But, have you tried this:

      select company
            ,postcode
            ,case when count(staff) != 0 then sum(bosses / staff) end your_alias
        from evaluation
    group by company, postcode;
    

    But is this really what you want? -Maybe something more in the lines of:

      select company
            ,postcode
            ,sum(case staff when 0 then 0 else bosses / staff end) your_alias
        from evaluation
    group by company, postcode;
    

    Concerning
    Peter

  • Left join between two tables using two different conditions

    I have following three tables with their data, as shown below.

    CREATE TABLE TIREMASTERPROCESS_TEMP
    (
    PRODUCTIONCODE TANK (12 BYTES),
    FIELDNAME CHAR (12 BYTES),
    DATACHR VARCHAR2 (60 BYTE),
    REVISIONNO TANK (3 BYTES),
    DATANUM NUMBER (9.4)
    )
    Whether the table c. and its sample data are like

    FIELDNAME DATACHR REVISIONNO DATANUM PRODUCTIONCODE
    AB No. Nch 1 100 0
    AB No. Nch 1 108 0
    AB No.-of-Nch 1 1 0
    Ass42 teased dishes 1 0
    Ass42 BTDrumNo1 BTD-051 1 0
    AB53 BTDrumNo1 BTD-051 104 0


    CREATE TABLE materialcode
    (
    UPPERMATERIALCODE CHAR (20),
    PROCESSNO TANK (3),
    PROCESSADOPTDATE TANK (9)

    )
    Whether the table b. and its sample data are like

    UPPERMATERIALCODE PROCESSNO PROCESSADOPTDATE
    Ass42 1 20120717
    AB53 108 20121121
    111 20111104 AS05
    104 20120928 AS30


    CREATE TABLE BUILDINGSCHEDULEMASTER
    (
    BUILDINGSIZE TANK (5 BYTES),
    GTCODE FLOAT (4 BYTES),
    TIREPERCART NUMBER (3.0).
    BUILDINGLOT NUMBER (3.0)
    )
    Whether table and its sample data are like

    BUILDINGSIZE GTCODE TIREPERCART BUILDINGLOT
    AB42A 4 12 ass42
    AB53A 4 88 AB53
    AS30A AS30 4 80
    BF03A 1 90 BF03


    Now, I need to get some data in these fields by using the suite of mappings.

    « PR_ » || Trim (a.BUILDINGSIZE) | ' / MPL2' Processid,--PRIMARY KEY
    TO_DATE (substr (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') starteff, to_date (SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') startDate.
    b.PROCESSNO revisioncodeid,
    a.BUILDINGLOT tirepercart ,
    CASE WHEN c.FIELDNAME = 'BTDrumNo1' then c.DATACHR end drumtype1.
    BOX WHEN (trim (C.DATACHR) = '1' and trim (C.FIELDNAME) = "No. Nch") and THEN click 'YES '.
    ANOTHER 'NO '.
    END may-BUG,
    case
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR = 'Use' THEN on 'YES '.
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR <>'Use' THEN 'NO '.
    fine wavy


    Now for the tables A and B I have the simple join as condition

    a.GTCODE = b.UPPERMATERIALCODE

    But I have to use two different left join conditions to join the table B and C to calculate the RESP fields according to the condition.
    Now, I have to use

    (trim (b.UPPERMATERIALCODE)). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    condition to get the data for the WAVY and DRUMTYPE1 fields.

    But at the same time, I have to use

    substr (Trim (b.UPPERMATERIALCODE), 1, 2). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    conition to derive the CHAFER field.

    And for this reason I am come so many duplicates and do not correct results for JUNEBUG, WAVY, DRUMTYPE1, and STARTDATE field.

    I need some advice as how can I do so that I get the correct results without duplicates for the PRIMARY KEY.

    Thank you

    Mahesh

    It would have been easier to answer if you gave us your example query that gives incorrect results - which both show us what you are doing and give us a starting point.
    Insert instructions for data, rather than only the data would have helped too, making it more quick to test this point.
    You do not show what you have done with your two outer join criteria, but I think you need to list TIREMASTERPROCESS_TEMP in your query twice, with alias names. Here's what I did:

    select a.BUILDINGSIZE, a.GTCODE, b.PROCESSNO ,  c1.FIELDNAME, c1.DATACHR, C2.FIELDNAME, C2.DATACHR
    , CASE WHEN c1.FIELDNAME='BTDrumNo1' then c1.DATACHR end drumtype1
    , CASE WHEN (trim(c2.DATACHR) = '1' and trim(c2.FIELDNAME) = 'No-of-Nch') THEN 'YES' ELSE 'NO' END CHAFER
    , case when c1.FIELDNAME='Wavy' AND c1.DATACHR='Use' THEN 'YES'
           when c1.FIELDNAME='Wavy' then 'NO' else null end wavy
    from BUILDINGSCHEDULEMASTER        A
    join materialcode b on a.GTCODE=b.UPPERMATERIALCODE
    left outer join TIREMASTERPROCESS_TEMP c1
       ON trim(b.UPPERMATERIALCODE)||'-'||trim(b.PROCESSNO) = trim(c1.PRODUCTIONCODE)||'-'||trim(c1.REVISIONNO)
    left outer join TIREMASTERPROCESS_TEMP c2
       ON substr(trim(b.UPPERMATERIALCODE),1,2)||'-'||trim(b.PROCESSNO) = trim(c2.PRODUCTIONCODE)||'-'||trim(c2.REVISIONNO)
    

    C1 is an alias for the TIREMASTERPROCESS_TEMP line which is necessary for drumtype1 and wavy, c2 is an alias for the TIREMASTERPROCESS_TEMP line required for JuneBug. There was some minor errors in your calculations of field I tried to correct.

    The results are:

    BUILD GTCO PRO FIELDNAME    DATACHR    FIELDNAME    DATACHR    DRUMTYPE1  CHA WAV
    ----- ---- --- ------------ ---------- ------------ ---------- ---------- --- ---
    AB53A AB53 108                         No-of-Nch    1                     YES
    AB42A AB42 1   BTDrumNo1    BTD-051    No-of-Nch    1          BTD-051    YES
    AB42A AB42 1   Wavy         NotUse     No-of-Nch    1                     YES NO
    AS30A AS30 104                                                            NO
    

    Hope this helps,
    David

  • Need help to implement a relationship between two Tables

    Hello

    According to the theory, relationship of individuals: each row in the table a related to a single line in table B.


    Any body could please show an example of script of such tables.

    Thanks for your advice. I would like that you recover too quickly to your illness, ask questions simple doc and doing nothing to fix them yourself. This is the reason why after 173 messages you can't write anything yourself.

    I saw your previous posts as (responded to some of them also)
    PL/SQL: ORA-00933: not correctly completed SQL command (Ask for the creation of a very simple procedure)
    How can I take backup of the Table with all the data (Ask how to take backup of a table)
    Writing a query to display data WHERE the data in column begin not with 'Rep' (Ask how to write a NO AS clause)

    One-to-one relationship is used in super type / sub-type relationship and there are many examples in asktom also (I got those using Google).

Maybe you are looking for

  • Satellite T130 - can I use a SSD?

    Is it posible to use SSDdisk in the Toshiba Satellite T130-K?

  • Install LV2009 SP1 - generator of Application activated but does not

    Installed the SP1.  Have activated the application builder in the License Manager.  Always impossible to run a build.  I see the yellow exclamation on my generations within projects. I tried many repairs and de-activations and re-activations.  I trie

  • questions/active ASA

    If I have of the asa configured as active/active. 1 - is treated as a single case? I mean I can only handle it with IDM? 2. the 5520 can have 130 000 connections. If I use 2 of what is active/active configuration, I can say that will get 130, 000 X 2

  • Impossible to add/edit Contacts blackBerry smartphones

    Hello My device coordinates are below:- 1. phone:-Blackberry 8520 Curve 2. OPERATING SYSTEM:-5.0 3. the claimant:-Vodafone India Whenever I tried to add / edit contacts, nothing happens just exceptions are thrown. I tried to erase safety data, but no

  • Divide a CSV with a regular Expression

    I'm working on a script that will read the CMYK values from a CSV file and add the nuances of the Swatches palette. I can easily split the CSV entering a comma (.split(",");), but I can't seem to get a regular expression to separate by commas and new