Help Newbie SQL

Hello

Someone understand me can explain why this SQL:

SELECT
R.r_ein FM, R.r_qtr QTR, S.s_class_title CLASS.
COUNT (CASE WHEN S.s_class_title = "Static"
THEN S.s_class_title
) AS static.

COUNT (CASE WHEN S.s_class_title = 'Dynamic'
THEN S.s_class_title
) AS dynamic.

COUNT (CASE WHEN S.s_class_title = "Strength of materials"
THEN S.s_class_title
) AS som

The REQUEST R, student S
WHERE R.r_id = S.s_request_id
AND (R.r_qtr = 'FY15Q4') OR
R.r_qtr = "FY15Q3") OR
R.r_qtr = "FY15Q2") OR
R.r_qtr = "FY15Q1")
)
GROUPING SETS (R.r_ein,(R.r_ein,S.s_class_title,R.r_qtr), NULL) GROUP
ORDER BY R.r_qtr, S.s_class_title

generates "ORA-00905: lack of keyword" when it is executed?

I'm counting the number of these classes of all others in the table.

Thank you

You need at the end of the CASE...

ORACLE-BASE - BOX Oracle Expressions and statements

Tags: Database

Similar Questions

  • Need help with Sql Tunning

    Under Update taking 2 h complete 3000 sets.

    UPDATE ARR_TRANSACTIONS ARR

    SET = NUMBER99

    (SELECT ARR_1.NUMBER99

    OF ARR_TRANSACTIONS ARR_1, ARR_HEADER BH

    WHERE ARR_1.ARR_ID = BH. ARR_ID

    AND BH. FLAG = "Y".

    AND ARR_1.LINE_ID = ARR. ORIG_INV_LINE_ID

    AND ARR_1.NUMBER9 IS NOT NULL

    AND ROWNUM = 1)

    WHERE ARR BATCH_ID = 26219

    AND ARR. NUMBER99 IS NULL

    I added more some condition where to reduce cost and its working fine. But I need to rise more than performance on SQL.

    Please help with SQL.

    I do not see the number of 3000 lines in the plan - so I guess that the optimizer does not compute with the correct numbers. Could generate the plan with dbms_xplan.display_cursor? This could tell us something about filter predicates and access.

    In the given situation, I would check:

    • is the access to the index in step 1 (filtered by the relevant conditions: this could be BATCH_ID = 26219) return actually 248 entries (or something similar)?
    • Access table in step 2 returning 204 lines (or something similar) after applying the filters given? If the number of lines is much bigger then a Nested Loops is perhaps not a good idea.

    To make this much simpler check, you could create a plan with statistics of content (RowSource) given that the plan containing the real and the number of estimated rows.

    If the estimated cardinalities are not plausible the next question would be if the statistics are strong and up to date.

  • need help with SQL Server 2008 R2 deadlock uninstall process

    I installed SQL Server 2008 R2 trial version on my PC running Windows Vista Ultimate, a day ago, but he placed himself completely in the disk partition (E :) that I specified. [i.e. I found some parts of the installation in my C:\program files as well as a USB as well].

    I tried to uninstall SQL Server 2008 R2, but was only partially successful.  I'm prevented from uninsalling the main parts using the programs and features Panel - that is "Microsoft SQL Server 2008 R2" and "Microsoft SQL Server 2008 R2 Setup (in English).

    Still visible are:

    1 C:\Program Files (x 86) \Microsoft SQL Server

    2 C:\Program Files (x 86) \Microsoft Visual Studio 9.0

    3 C:\ProgramData\Microsoft\Windows\Start demarrer\programmes\microsoft SQL Server 2008 R2

    I would like your help to uninstall the other goals of SQL Server, so that I can do a clean install once more.

    Any advice on how SQL Server 2008 R2 evaluation version must be correctly installed what a future unistall is not messy, would be welcome.

    Hello

    Your question of Windows 7 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the SQL Server forums. Please post your question in the SQL Server forums.

    http://social.msdn.Microsoft.com/forums/en/category/SQLServer

  • Need help with sql, and bash

    Hi guys,.

    My main problem/situation is when sqlplus returns no data (no message selected lines)

    Bash shell script condition

    echo $open_items

    15 if [[$open_items == "0"]]

    16. can

    echo 17 0

    18 else

    19 1 echo

    20 fi

    and real sql is as follows:

    elect the count (*) a table with a condition.

    I get the output as follows:

    + open_items ='

    COUNT (*)

    ----------

    0'

    + echo 'COUNT (*)'---0

    COUNT ()) - 0

    + [[

    COUNT (*)

    ----------

    0 == \0 ]]

    + echo 1

    1

    What to do so that I can get a number in the output of sql is my question because the condition of shell script is based entirely on sqlplus out. I tried set feedback off, but it does not help.

    Any help would be much appreciated!

    SQL lover wrote:

    OK I try it and give you feedback

    In fact, I take out execution of sql into a variable

    MyVar = $(sqlplus-s/as sysdba)<>

    Set echo off feedback off verify off trimsp head off pages 0

    Select count (*) from dba_users;

    output

    EXPRESSIONS OF FOLKLORE)

    echo myvar is $myvar

  • Need help pl/sql

    Dear team,

    I have a technical dought based on PL/SQL.

    I have a code like below

    Select count (*)

    in lcnt_al per_absence_attendances where person_id = p_person_id

    and absence_attendance_type_id in (61,62)

    and (p_from_date between date_start and date_end or p_to_date between date_start and date_end);

    Scenario:

    If I have a leave as records

    Type of Date to Date Absence days

    Leave annual 6 may 2015 10 May 15, 2015

    Loss of wages may 16, 2015 may 20, 2015 5

    If I use the above condition, it works very well.

    If am I on May 1, 2015 may 21, 2015, my condition is declining. It's the bcz there is no record exists in this period.

    But still he must fail, bcz between dates exist.

    Can any help in this.

    Thank you

    Thank you all,

    I solved my problem. Thanks to all who helped me.

    Thank you

  • Help on sql

    Hello

    I have a table that has the month_key column. Need to find the current_month-36.

    Month_key = output expected 201503 = 36 months before the current month which is 201203.

    How can I get sql to get 201203 r. p. output format.

    Thank you

    Hello

    Daniel wrote:

    First I need to find the current month in this format 201503

    and find currentmonth-36 which is 201203

    Please help in obtaining sql.

    Why do you need to find the current month if you already have a column (month_key) that contains the data?  This is an example of why you should validate CREATE TABLE and INSERT for examples of data and instructions exactly the results you want from these data.

    The function SYSDATE returns the current date, including the months.

    In response, #2, you've seen how to find a DATE that was 36 months before another DATE.

    ADD_MONTHS (SYSDATE-36)

    is the DATE of 36 months ago to the day.

    Use the TO_CHAR function if you want to display a DATE in a particular format, like this:

    TO_CHAR (ADD_MONTHS (SYSDATE-36)

    , "YYYYMM.

    )

  • Need help with sql query

    Dear all,

    I have a sql like query below

    SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER

    MTL_TXN_REQUEST_HEADERS D,.

    MTL_TXN_REQUEST_LINES, E.

    MTL_MATERIAL_TRANSACTIONS G,.

    Mtl_Transaction_Types I have

    WHERE D.HEADER_ID = E.HEADER_ID

    AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID

    AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')

    AND E.LINE_ID = G.MOVE_ORDER_LINE_ID

    AND D.MOVE_ORDER_TYPE = 5

    TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')

    D.REQUEST_NUMBER GROUP

    I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.

    above query is back under results

    results.jpg

    If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.

    so in the example above, it must return

    FIRST REQUEST NUMBER LAST NUMBER

    2383                                      1886

    Thank you

    select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min
         , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max
      from (
            select min(g.transaction_date) transaction_date
                 , d.request_number
              from mtl_txn_request_headers d
                 , mtl_txn_request_lines e
                 , mtl_material_transactions g
                 , mtl_transaction_types i
             where d.header_id                    = e.header_id
               and g.transaction_type_id          = i.transaction_type_id
               and upper(i.transaction_type_name) = upper('WIP Issue')
               and e.line_id                      = g.move_order_line_id
               and d.move_order_type              = 5
               and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014')
             group
                by d.request_number
           )
    
  • Need help with sql query performance

    Dear all,

    I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.

    Select rownum LINE_NUM,

    A.LINE_ID,

    TO_CHAR (A.INVITMID),

    TO_NUMBER (A.PICKQTY),

    UNLOADINGPNT NULL,

    RRNUM NULL,

    WORKORDNUM NULL,

    WORKORDDESC NULL,

    A.PONUM,

    DTR_DUMB NULL,

    A.DESCRIPTION,

    FROM_SUB NULL,

    TO_SUB NULL,

    NO SOURCE,

    ASSET_NUMBER NULL,

    A.RECEIPTNUM,

    MOVEORD NULL,

    FROM_LOC NULL,

    TO_LOC NULL,

    MSD_NUM NULL,

    CONTAIN_LINE NULL,

    A.UOM,

    A.PO_RELEASE

    de)

    Select headerid Po.Po_Header_Id,

    rcv1. Po_Line_Id LINE_ID,

    rcv1.item_id INVITMID,

    (NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,

    Po.Segment1 PONUM,

    Rcv1.Receipt_Num RECEIPTNUM,

    Rcv1.Item_Desc DESCRIPTION,

    Rcv1.Transact_Uom GLU,

    Rcv1.Po_release

    Po_Headers_All in.,.

    (Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)

    SELECT A.Po_Header_Id,

    C.RECEIPT_NUM receipt_num,

    A.Po_Line_Id,

    A.Destination_Type_Code,

    B.Item_Id,

    B.item_description Item_Desc,

    A.UNIT_OF_MEASURE Transact_Uom,

    A.QUANTITY Transact_Qty,

    D.RELEASE_NUM PO_RELEASE

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND UPPER (A.Transaction_Type) = "to DELIVER".

    AND higher (A.Destination_Type_Code) = "EXPENSES".

    AND D.PO_RELEASE_ID = A.PO_RELEASE_ID

    UNION ALL

    SELECT A.Po_Header_Id,

    C.RECEIPT_NUM receipt_num,

    A.Po_Line_Id,

    A.Destination_Type_Code,

    B.Item_Id,

    B.item_description Item_Desc,

    A.UNIT_OF_MEASURE Transact_Uom,

    A.QUANTITY Transact_Qty,

    D.RELEASE_NUM PO_RELEASE

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND B.ITEM_ID IS NULL

    AND UPPER (A.Transaction_Type) = "to DELIVER".

    AND higher (A.Destination_Type_Code) = "WORKSHOP".

    D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3

    GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),

    (SELECT A.PO_LINE_ID,

    Sum (A.Quantity) transact_qty,

    A.PO_HEADER_ID,

    C.RECEIPT_NUM

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"

    AND D.PO_RELEASE_ID = A.PO_RELEASE_ID

    A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2

    Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)

    And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)

    And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)

    And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)

    Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has

    Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    Please find the attached PLAN to EXPLAIN.

    EXPLAINPLAN.jpg

    Thank you

    May be essentially the same join (between a, b, c and d) twice instead of three times

    sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2

    We can work on what we can see only

    Select rownum line_num,

    rcv1.po_line_id line_id,

    TO_CHAR (rcv1.item_id) invitmid,

    NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,

    unloadingpnt null,

    rrnum null,

    workordnum null,

    workorddesc null,

    Po. Ponum Segment1,

    dtr_dumb null,

    description of the rcv1.item_desc,

    from_sub null,

    to_sub null,

    No source,

    asset_number null,

    rcv1.receipt_num receiptnum,

    moveord null,

    from_loc null,

    to_loc null,

    msd_num null,

    contain_line null,

    Glu rcv1.transact_uom,

    rcv1.po_release

    of po_headers_all in.

    left outer join

    (select a.po_header_id,

    c.receipt_num,

    a.po_line_id,

    a.destination_type_code,

    b.item_id,

    b.item_description item_desc,

    a.unit_of_measure transact_uom,

    Sum (a.Quantity) transact_qty,

    d.release_num po_release

    from (select shipment_header_id,

    shipment_line_id,

    po_release_id,

    po_header_id,

    po_line_id,

    destination_type_code,

    unit_of_measure,

    quantity

    of rcv_transactions

    where upper (a.transaction_type) = "to DELIVER".

    and upper (a.destination_type_code) ('charge', 'WORKSHOP')

    ) a

    inner join

    rcv_shipment_lines b

    On a.shipment_line_id = b.shipment_line_id

    inner join

    c rcv_shipment_headers

    On a.shipment_header_id = c.shipment_header_id

    left outer join

    po_releases_all d

    On a.po_release_id = d.po_release_id

    where upper (a.destination_type_code) = "EXPENSES".

    or (upper (a.destination_type_code) = 'WORKSHOP'

    and b.item_id is null

    )

    A.po_header_id group,

    c.receipt_num,

    a.po_line_id,

    a.destination_type_code,

    b.item_id,

    b.item_description,

    a.unit_of_measure,

    d.release_num

    ) rcv1

    On po.po_header_id = rcv1.po_header_id

    left outer join

    (select a.po_line_id,

    Sum (a.Quantity) transact_qty,

    a.po_header_id,

    c.receipt_num

    from (select shipment_header_id,

    shipment_line_id,

    po_release_id,

    po_header_id,

    quantity

    of rcv_transactions

    where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.

    ) a

    inner join

    rcv_shipment_lines b

    On a.shipment_line_id = b.shipment_line_id

    inner join

    c rcv_shipment_headers

    On a.shipment_header_id = c.shipment_header_id

    left outer join

    po_releases_all d

    On a.po_release_id = d.po_release_id

    A.po_line_id group,

    a.po_header_id,

    c.receipt_num

    ) rcv2

    On rcv1.po_line_id = rcv2.po_line_id

    and rcv1.receipt_num = rcv2.receipt_num

    where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)

    Concerning

    Etbin

  • Need help with SQL/PL/SQL for Dates

    Hi Experts - need help with a SQL query.

    I need to insert some date fields in a table called CALENDAR_PERIOD.

    Current data in CALENDAR_PERIOD table with their data types:

    STARTPERIOD (DATE) YEAR (NUMBER) PERIOD_LABEL (Varchar2 255)

    02/11/2014 2014 2014/02/11 SUN

    03/11/2014 2014 14/03/11 MON

    04/11/2014 2014 11/04/14 MAR

    I have to increment above values up to the year 2025. I don't know how to write SQL and increment of these values.

    Ex: My next value should insert: 05/11/2015 2014 11/05/14 WED like that I need to insert data until 12 31, 2025.

    Can you please help me with PL/SQL block?

    Really appreciate your help!

    DB version:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    Thank you
    Sandy

    Hello Sandy,

    Maybe something like

    INSERT INTO calendar_period (startperiod, year, period_label)

    SELECT DATE '' 2014-11-04 + LEVEL

    , TO_NUMBER (TO_CHAR (DATE '' 2014-11-04 + LEVEL, "YYYY"))

    , TO_CHAR (DATE '' 2014-11-04 + LEVEL, "MM/DD/YY DY")

    OF the double

    CONNECT BY LEVEL<= date="" '2025-12-314="" -="" date="">

    ;

    ((mais je ne comprends pas pourquoi nous créons une telle table "année" et "period_label" peuvent être calculé à partir de startperiod))

    Best regards

    Bruno Vroman.

  • need help with sql queries

    Dear all,

    I have a parameter like below

    11000048,11000050

    I need to convert in SQL format below, please help me

    "11000048","11000050"


    ' parameter would be so separated by commas, I need to convert in above format, if the parameter is a number say 1111111 must convert it as "1111111" in sql.


    Please help me.


    Thank you

    You can do it

    your_parameter: = "" ' | " Replace (your_parameter, ",", "",""). '"';

  • Need help on SQL


    Please help me on the following sql.

    TABLE 1:

    IS_OUTL_IDHRS_TYP_CDEFFECTIVE_DATE
    IS04408ATM5 JUNE 13
    IS04408CUSTDSPOCTOBER 5, 13
    IS04408DRVTLRNOVEMBER 5, 13

    TABLE 2:  This table will have future effective dates for a particular record. We have to search on the second table and take the entry into force and mark as previous record end date.

    IS_OUTL_IDHRS_TYP_CDEFFECTIVE_DATE
    IS04408CUSTDSPNOVEMBER 5, 13
    IS04408CUSTDSP2 JANUARY 14

    RESULT:

    IS_OUTL_IDHRS_TYP_CDEFFECTIVE_DATEEND_DATE
    IS04408ATM5 JUNE 13
    IS04408DRVTLRNOVEMBER 5, 13
    IS04408CUSTDSPOCTOBER 5, 13NOVEMBER 4, 13
    IS04408CUSTDSPNOVEMBER 5, 131 JANUARY 14
    IS04408CUSTDSP2 JANUARY 14

    Hello

    Therefore, each line of output, that you want to include end_date, based on a value between similar line, when there is one.

    This looks like a job for the analytical function of LEAD, something like this:

    WITH union_data AS

    (

    SELECT is_outl_id, hrs_typ_cd, effective_date

    FROM table_1

    UNION ALL

    SELECT is_outl_id, hrs_typ_cd, effective_date

    FROM table_2

    )

    SELECT is_outl_id, hrs_typ_cd, effective_date

    Advance (effecive_date) OVER (PARTITION BY hrs_typ_cd

    , is_outl_id - can - be

    ORDER BY effective_date

    ) - 1 AS end_date

    Of union_data

    ORDER BY is_outl_id - can - be

    hrs_typ_cd

    effective_date

    ;

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Report when the above query is to give erroneous results and explain, using specific examples, how to get the correct results of data provided in these places.  If you have changed the query at all, your postal code.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Another newb SQL error

    Following the advice I got from my last topic I created now my tables and now I want to fill it with my data but I get an error

    Here is my sql command complete. Since the last time, I learned that a foreign key can be implemented in a single table and cannot be reproduced

    to work around this problem, I changed my foreign key as you can see in "fkone" . But why make me errors when trying to add information

    I want to say that I did get errors in the first two tables so that I am ""hurts / not understand " "

    CREATE THE CUSTOMER TABLE)
    CUSTOMERNAME varchar (25),
    STREET varchar (25),
    CUSTOMERCITY varchar (25),
    CONSTRAINT CUSTOMER_pk PRIMARY KEY (CUSTOMERNAME));

    CREATE TABLE DEPOT)
    CUSTOMERNAME varchar (25),
    BRANCHNAME varchar (25),
    Int ACCOUNTNUMBER,
    Decimal (7.2), the balance
    CONSTRAINT DEPOSIT_pk PRIMARY KEY (ACCOUNT number));

    CREATE TABLE READY)
    CUSTOMERNAME varchar (25),
    BRANCHNAME varchar (25),
    LOANNUMBER int,
    Decimal AMOUNT (7.2),
    CONSTRAINT LOAN_pk PRIMARY KEY (LOANNUMBER));

    CREATING A TABLE BRANCH)
    BRANCHNAME varchar (25),
    BRANCHCITY varchar (25),
    ASSETS in decimals (7.2),
    CONSTRAINT BRANCH_pk PRIMARY KEY (BRANCHNAME));

    ALTER TABLE DEPOT
    Add CONSTRAINT fk_BRANCH
    FOREIGN KEY (BRANCHNAME)
    BRANCH (BRANCHNAME) REFERENCES
    WE DELETE CASCADE;

    ALTER TABLE DEPOT
    Add CONSTRAINT fk_CUSTOMER
    FOREIGN KEY (CUSTOMERNAME)
    REFERENCES CUSTOMERS (CUSTOMERNAME)
    WE DELETE CASCADE;

    ALTER TABLE READY
    Add CONSTRAINT fkone_BRANCH
    FOREIGN KEY (BRANCHNAME)
    BRANCH (BRANCHNAME) REFERENCES
    WE DELETE CASCADE;

    ALTER TABLE READY
    Add CONSTRAINT fkone_CUSTOMER
    FOREIGN KEY (CUSTOMERNAME)
    REFERENCES CUSTOMERS (CUSTOMERNAME)
    WE DELETE CASCADE;

    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES ('YORKSHIRE', 'NOTTINGHAM', ' 10000');
    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES (' MIDLANDS', 'NOTTINGHAM',' 20000 ');
    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES ('ROYALBANK', 'NOTTINGHAM', ' 25000');
    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES ("HFE", 'DERBY', '15000');
    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES ('SOUTH', 'DERBY', '30000');

    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ("JONES", "VICTORIA", "NOTTINGHAM");
    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ('STONE', 'CHURCH', 'NOTTINGHAM');
    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ('SMITH', 'DERBY', 'LEICESTER');
    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ("AHMED", "CHURCH", "DERBY");
    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ('BRAUN', "ALFRED", "DERBY");
    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ('CHAN', 'VICTORIA', 'NOTTINGHAM');

    Problems occur when you try to insert the following data in my tables

    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES (' JONES', 'YORKSHIRE', ' 1 ', 100' ");
    INSERT INTO DEPOT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('BRAUN', '' MIDLANDS, '20', 150');
    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('AHMED', 'ROYALBANK', '30', '480');
    INSERT INTO DEPOT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('SMITH', '' MIDLANDS, '21', 600');


    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('STONE', 'ROYALBANK', '31', '450');
    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('STONE', '' MIDLANDS, '22', 70');
    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('BRAUN', 'SOUTH', ' 41 "," 2000");
    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES (' JONES', "HFE", ' 42 ', 4100' ");

    ERROR on line 1:

    ORA-02291: integrity constraint (N0430265. FK_CUSTOMER) violated - parent key does not

    If you're wondering what I'm trying to achieve is the task I'm supposed to do.

    1. Add the following four tables for your
      database by using the SQL CREATE TABLE statement (stressed primary keys)

    Customer
    (customerName, street customerCity)

    1. Deposit
      (customerName, branchName, account number,
      balance) - where branchName and customerName are the foreign keys to tables Branch
      and the client.
    2. Loan
      (customerName, branchName, loanNumber,
      amount) - where branchName and customerName are the foreign keys to tables Branch
      and the client.
    3. Directorate-General of the
      (branchName, branchCity, assets).

    2. Add
    the following data rows for each table using the INSERT command:




    Directorate-General of the



    branchName





    assets



    branchCity



    Yorkshire





    10000



    Nottingham



    Midlands





    20000



    Nottingham





    Customer



    customerName





    Street



    customerCity



    Jones





    Victoria



    Nottingham



    Patel





    Church



    Nottingham



    Deposit





    customerName



    branchName



    Account number



    Balance



    Jones



    Yorkshire



    1



    100







    Loan





    customerName



    branchName



    loanNumber



    amount



    Jones



    Yorkshire



    11



    3000


    Thank you for taking your time to help I appreciate all of your comments I get this can improve my SQL because I am in it and I want to my class of ace

    I let down all the tables and copy them and paste in oracle and see what I get atm cause I get the same error, but cannot determine where I'm wrong

    CuriousStudentJo wrote:

    Following the advice I got from my last topic I created now my tables and now I want to fill it with my data but I get an error

    Here is my sql command complete. Since the last time, I learned that a foreign key can be implemented in a single table and cannot be reproduced

    to work around this problem, I changed my foreign key as you can see in "fkone". But why make me errors when trying to add information

    I want to say that I have not gotten errors in the first two tables until I have "hurt / not understand."

    CREATE THE CUSTOMER TABLE)
    CUSTOMERNAME varchar (25),
    STREET varchar (25),
    CUSTOMERCITY varchar (25),
    CONSTRAINT CUSTOMER_pk PRIMARY KEY (CUSTOMERNAME));

    CREATE TABLE DEPOT)
    CUSTOMERNAME varchar (25),
    BRANCHNAME varchar (25),
    Int ACCOUNTNUMBER,
    Decimal (7.2), the balance
    CONSTRAINT DEPOSIT_pk PRIMARY KEY (ACCOUNT number));

    CREATE TABLE READY)
    CUSTOMERNAME varchar (25),
    BRANCHNAME varchar (25),
    LOANNUMBER int,
    Decimal AMOUNT (7.2),
    CONSTRAINT LOAN_pk PRIMARY KEY (LOANNUMBER));

    CREATING A TABLE BRANCH)
    BRANCHNAME varchar (25),
    BRANCHCITY varchar (25),
    ASSETS in decimals (7.2),
    CONSTRAINT BRANCH_pk PRIMARY KEY (BRANCHNAME));

    ALTER TABLE DEPOT
    Add CONSTRAINT fk_BRANCH
    FOREIGN KEY (BRANCHNAME)
    BRANCH (BRANCHNAME) REFERENCES
    WE DELETE CASCADE;

    ALTER TABLE DEPOT
    Add CONSTRAINT fk_CUSTOMER
    FOREIGN KEY (CUSTOMERNAME)
    REFERENCES CUSTOMERS (CUSTOMERNAME)
    WE DELETE CASCADE;

    ALTER TABLE READY
    Add CONSTRAINT fkone_BRANCH
    FOREIGN KEY (BRANCHNAME)
    BRANCH (BRANCHNAME) REFERENCES
    WE DELETE CASCADE;

    ALTER TABLE READY
    Add CONSTRAINT fkone_CUSTOMER
    FOREIGN KEY (CUSTOMERNAME)
    REFERENCES CUSTOMERS (CUSTOMERNAME)
    WE DELETE CASCADE;

    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES ('YORKSHIRE', 'NOTTINGHAM', ' 10000');
    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES (' MIDLANDS', 'NOTTINGHAM',' 20000 ');
    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES ('ROYALBANK', 'NOTTINGHAM', ' 25000');
    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES ("HFE", 'DERBY', '15000');
    INSERT INTO BRANCH (BRANCHNAME, BRANCHCITY, ASSETS) VALUES ('SOUTH', 'DERBY', '30000');

    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ("JONES", "VICTORIA", "NOTTINGHAM");
    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ('STONE', 'CHURCH', 'NOTTINGHAM');
    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ('SMITH', 'DERBY', 'LEICESTER');


    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ("AHMED", "CHURCH", "DERBY");
    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ('BRAUN', "ALFRED", "DERBY");
    INSERT INTO CUSTOMER (CUSTOMERNAME, STREET, CUSTOMERCITY) VALUES ('CHAN', 'VICTORIA', 'NOTTINGHAM');

    Problems occur when you try to insert the following data in my tables

    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES (' JONES', 'YORKSHIRE', ' 1 ', 100' ");
    INSERT INTO DEPOT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('BRAUN', '' MIDLANDS, '20', 150');
    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('AHMED', 'ROYALBANK', '30', '480');
    INSERT INTO DEPOT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('SMITH', '' MIDLANDS, '21', 600');
    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('STONE', 'ROYALBANK', '31', '450');
    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('STONE', '' MIDLANDS, '22', 70');
    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES ('BRAUN', 'SOUTH', ' 41 "," 2000");
    INSERT INTO DEPOSIT (CUSTOMERNAME, BRANCHNAME, ACCOUNT NUMBER, BALANCE) VALUES (' JONES', "HFE", ' 42 ', 4100' ");

    ERROR on line 1:

    ORA-02291: integrity constraint (N0430265. FK_CUSTOMER) violated - key parent not found

    If you're wondering what I'm trying to achieve is the task I'm supposed to do.

    1. Add the following four tables for your
      database by using the SQL CREATE TABLE statement (stressed primary keys)

    Customer
    (customerName, street customerCity)

    1. Deposit
      (customerName, branchName, account number,
      balance) - where branchName and customerName are foreign keys to tables Branch
      and the client.
    2. Loan
      (customerName, branchName, loanNumber,
      amount) - where branchName and customerName are foreign keys to tables Branch
      and the client.
    3. Directorate-General of the
      (branchName, branchCity, assets).

    2. Add
    the following data rows for each table using the INSERT command:

    Directorate-General of the

    branchName
     

    assets
     

    branchCity
     

    Yorkshire

    10000

    Nottingham

    Midlands

    20000

    Nottingham

    Customer

    customerName
     

    Street

    customerCity
     

    Jones

    Victoria

    Nottingham

    Patel

    Church

    Nottingham

    Deposit
     

    customerName
     

    branchName

    Account number

    Balance
     

    Jones

    Yorkshire

    1

    100

    Loan
     

    customerName

    branchName

    loanNumber

    amount

    Jones

    Yorkshire

    11

    3000

    Thanks for taking your time to help I appreciate every feedback I get this can improve my SQL because I am in it and I want to my class of ace

    I DROP ALL THE TABLES AND COPIED AND PASTED THE DATA AND LINES WHERE CREATED SO I DON'T KNOW WHERE THIS PROBLEM BUT THANKS AGAIN GUYS I TOTALLY A STEP CLOSER

    UNDERSTANDING SQL

  • Help on SQL Pivot


    Hi gurus,
    I have req where I need to make the comparison between the Bill of trial ordinary bill vs. I need to get the test of the previous months and the latest current_month and 2 months of regular bills. Here are the th sample data.


    Account # Invc # Start_Date end_date regular_Amoun t Trial_Amount
    1233456 26470000 June 1, 2013 July 1, 2013 $19 27
    1347589 26470000 August 1, 2013 current_date $45 67
    1115756 26470000 may 1, 2013 July 1, 2013 $39 27

    This is the desired output

    Account # Invc # June 2013, July, 2013 August 2013
    1233456 26470000 $39 19 $ $67

    Any contribution is appreciated

    Hello

    Depending on your needs, here's a way:

    WITH got_month_num AS

    (

    SELECT account # invc #, regular_amount, trial_amount

    TRUNC (MONTHS_BETWEEN (start_date

    ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'),

    - 3

    )

    )

    ) AS month_num

    FROM table_x

    WHERE the arguments start_date > = ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'),-2)

    AND start_date<  add_months="" (trunc="" (sysdate,="" 'month'), ="">

    )

    SELECT MIN (CASE WHEN month_num = 2 THEN accountt # END) AS account #.

    invc #.

    SUM (CASE WHEN month_num = 1 THEN regular_amount END) AS month_before_last

    SUM (CASE WHEN month_num = 2 THEN regular_amount END) AS last_month

    SUM (CASE WHEN month_num = 1 THEN trial_amount END) AS this_month\

    OF got_month_num

    GROUP BY invc #.

    ;

    It would take to get the columns as AUG_2013 dynamic SQL alias.  Your front end can help with that.  In SQL * Plus, for example, you can use substitution variables.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Point where the above query is incorrect results, and explain, using specific examples, how you get the right result of data provided in these places.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).  In this problem, what front-end you use (for example, SQL * Plus version 10) may also be important.

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Help with SQL Query (Subselects)

    Hello community,

    IAM a new Member in this forum. The first excuse my English, my native language is German.
    In my workplace, we have a great Orcle Database 11 g with 30 different tables for production control issues.
    I try to get a couple of different information from the database, so I started with SQL of the query, but for this problem, I wasn't able to write a query to work.

    In this case, I have 2 tables:
    Table 1:
    ID; ORDER_NR; DESCRIPTION; CREATE_DATE
    1; A500236; CLEAN HOUSE; 20/02/2012
    2; A623555; REPAIR CAR; 10/01/2012
    3; A866944; MAINTAIN EQUIPMENT; 11/02/2012

    Table 2:
    ID; ORDER_NR; WO_STEP; STEP_DATE; EMPLOYEE
    1; A500236; A; 21/02/2012; W0010
    2; A500239; F; 21/02/2012; W0010
    3; A500239; S; 22/02/2012; W0027
    4; A500239; R; 23/02/2012; H0034
    5; A500239; U; 25/02/2012; L0099
    6; A263555; A; 15/01/2012; G0009
    7; A263555; C; 17/01/2012; S0039
    5 V A263555; R; 18/01/2012; K0059
    9; A263555; U; 19/01/2012; A0048
    10; A866944; A; 13/02/2012; H0034
    11; A866944; B; 13/02/2012; L0035
    12; A866944; G; 17/02/2012; D0084
    13; A866944; U; 23/02/2012; S0039

    And the result of my query should look like this:
    ORDER_NR; DESCRIPTION; CREATE_DATE; A_STAT_AGE; R_STAT_AGE; U_STAT_AGE
    A500236; OWN HOME; 20/02/2012; 5; 3; 1
    A623555; REPAIR CAR; 01/10/2012; 42; 39; 38
    A866944; MAINTAIN EQUIPMENT; 11/02/2012; 15; 4; 3

    The age of my query result should be calculated from the date of the creation of the order.
    I would like to know 2 things, one is how old was the order when they reached this status, R and U.
    The second, that is, how long did you order remaining on A stat, R and U (and if possible all the others too)
    It can happen that not every order reaches every State, so he ca go directly from A you in this case I want to display a generic character in this row/column

    I hope you all know what I mean and what result to expect.

    Thanks for your help.

    Reinhard W.

    Hi, Reinhard,

    990524 wrote:
    Hi Frank,.

    I thank you for your professional response and excuse my non-professional way to clarify my question.
    I have now already read and understand how to ask good questions, but is there an easy an inexpensive way to run a database on my computer at home?

    You can download the Oracle database from this site. The Express edition is easier to install. It lacks a few features that the Enterprise edition (for example, partitioning table and safety of level line), but most of the things work in all editions of Oracle.
    All editions are free if you do not use them for Production applications. Of course, at this price (or lack thereof), you get Oracle support.

    I have already noticed that the syntax SQL for Oracle differ from other DBMSS.

    Yes and some features are different in different products.

    Your query works perfectly, thank you.

    Now I want to refine my (your) query, is there a way to display a range of day within 1 day? As 0.5 day to half a day between two State timestamp.

    Of course, you can do it. After the exact output desired of the sample data that I posted. If the sample data do not show what you need to do, then after a few different examples of data that makes.

    My table contains the Date and time in a row, I forgot to mention that.

    After a CREATE TABLE statement. I was guessing a lot of things that may be important. For example, I assumed you were using a DATE for date and time column. So it is only reasonable to do so, but maybe it's not what looks like at your table.

    I tried something like this:

    SYSDATE - MIN ( CASE
                        WHEN  t2.wo_step = 'A'
                  THEN  t2.step_date
              END
               ) AS Age_A
    

    But it gives me an error of arithmetic overflow and not die difference in the Date and time or days with decimal friction.

    There are only about 5.4 million possible days with DATEs of Oracle. Is only 7 digits and Oracle can treat approximately 39 numbers without overflow errors, so I don't see how this can happen if t2.step_date is really a DATE. This is an example of why you need to publish a CREATE TABLE statement.

  • Where clause ' where 1 = 1 ' help with SQL tuning

    Hello Tuning specialists,.
    It is useful to use ' where 1 = 1 ' and then type all joins and conditions in the statements 'AND' of the SQL when writing SQL queries. I would like to know if it helps with the writing queirs this way SQL query performance.

    Thanks in advance.

    Published by: oracle_developer on October 8, 2012 10:41

    oracle_developer wrote:
    Hello Tuning specialists,.
    It is useful to use ' where 1 = 1 ' and then type all joins and joins in the statements "AND" when writing SQL queries.
    I would like to know if it helps with the writing queirs this way SQL query performance.

    He has No. performance impact.
    It is done when building dynamic SQL, so each sentence can start with AND

Maybe you are looking for