1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

showing total of PRICE using 3 tables PROBLEM URGENT??

Discussion in 'Databases' started by nvidia, Jan 16, 2007.

  1. #1
    I am using three tables for this, customer table, orders table and orderline table. When a user enters a orderid, the program should display the total order for a certain orderid. how can i use the SUM function in such a way that i can store the total order cost(price of orders) in a variable and display it in the ouput line function??

    
    
    SET SERVEROUTPUT ON;
    DECLARE
    v_odNum NUMBER(8):= &sv_orderNum;
    v_price NUMBER(7,2);
    v_quantity NUMBER(5);
    
    v_fname VARCHAR2(30);
    v_lname VARCHAR2(30);
    v_add VARCHAR2(30);
    
    BEGIN
    SELECT first, last, cadd, order_price, quantity, SUM(order_price * quantity) AS TOTAL
    INTO v_fname, v_lname, v_add, v_price, v_quantity
    FROM customer c, orders o, orderline ordl
    WHERE c.custid = o.custid AND o.orderid = ordl.orderid
    AND v_odNum = o.orderid
    
    DBMS_OUTPUT.PUT_LINE('The total order for' ||v_odNum|| ' '|| 'is' || TOTAL);
    END;
    /
    
    Code (markup):
    If you like to see how the tables look tell me please.
     
    nvidia, Jan 16, 2007 IP
  2. smallbuzz

    smallbuzz Peon

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    SELECT first, last, cadd, order_price, quantity, SUM(order_price * quantity) AS TOTAL
    INTO v_fname, v_lname, v_add, v_price, v_quantity, v_total
    FROM customer c, orders o, orderline ordl
    WHERE c.custid = o.custid AND o.orderid = ordl.orderid
    AND v_odNum = o.orderid
    group by first, last, cadd, order_price, quantity
     
    smallbuzz, Jan 16, 2007 IP
  3. smallbuzz

    smallbuzz Peon

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Whatever column that is not in a function, you have to put them in the group by clause.
     
    smallbuzz, Jan 16, 2007 IP