--%>

Compute the Total Shopper Spending in SQL

Most of the reports produced from the system compute the total dollars in purchases for a shopper. Process the following steps to build a function named TOT_PURCH_SF which accepts a shopper id as input and returns the total dollars which the shopper has spent with company. Utilize the function in a SELECT statement which shows the shopper id and total purchases for each and every shopper in a database.
 
1. Make and run a CREATE FUNCTION statement to build the TOT_PURCH_SF function. The function code requires a formal parameter for the shopper id and to sum the total column from the BB_BASKET table.

2. Form a SELECT statement employing the BB_SHOPPER table to generate a list of each shopper in the database and his/her respective totals.

E

Expert

Verified

create or replace function "TOT_PURCH_SF" (shopper_id in NUMBER)
return NUMBER is TOTAMT NUMBER;

begin

SELECT SUM(TOTAL) INTO TOTAMT FROM BB_BASKET WHERE IDSHOPPER=SHOPPER_ID GROUP BY IDSHOPPER;

dbms_output.put_line (totamt);

RETURN TOTAMT;

end;

   Related Questions in Programming Languages

  • Q : What is Shallow copy Shallow copy : It

    Shallow copy: It is a copy of an object in which copies of each and every object's sub-components are not as well made. For example, a shallow copy of an array of objects would outcome in two separate array objects, each having references to similar s

  • Q : Explain Assignment operator Assignment

    Assignment operator: The operator (=) employed to store the value of an expression into the variable, for example: Variable = expression; The right-hand

  • Q : Function of STR and LPSTR Explain what

     Explain what is the function of STR and LPSTR?

  • Q : What is BLAST in program model checking

    What is BLAST in program model checking: The abbreviation is Berkeley Lazy Abstraction Software Verification Tool (BLAST) is a software model checker for C programs. The main goal of BLAST (BLAST website) is to be able to check that software satisfies

  • Q : Explain Do loop Do loop : This is one

    Do loop: This is one of Java's three control structures employed for looping. The other two are the for loop and while loop. A do loop comprises of a loop body and a Boolean expression. The condition is tested subsequent to the loop body has been fini

  • Q : Differences between logical and

    What are the differences between logical and physical address spaces?

  • Q : Commands used to create the files

    Specify different commands which are used in order to create the files?

  • Q : ASP.NET Session handling How to set

    How to set Session time out in ASP.NET. I tries changing in config file but still facing issue. Please help..

  • Q : Explain If statement If statement : A

    If statement: A control structure employed to select between performing or not performing additional actions.     if(boolean-expression){        // Statements

  • Q : Define the term Field Define the term

    Define the term Field: Variables stated within a class or interface, exterior of the methods. The fields are members of a class.