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 : Define Accessor method Accessor method

    Accessor method: A technique specifically designed to offer access to a private attribute of a class. By convention, we name accessors with a get prefix followed by the name of the attribute being accessed. For example, the accessor for an attribute n

  • Q : Monte Carol method to estimate pi An

    An interesting way to estimate pi can can done using Monte Carol method with minimal mathematics. Monte Carlo is known for its casinos. A Monte Carlo method uses change, or in our case, random numbers to simulate the real situation. The situation we simulate here is t

  • Q : Define Unicode Unicode : It is a 16-bit

    Unicode: It is a 16-bit character set designed to make it simpler to exchange and exhibit information which makes use of a broad range of dissimilar languages and symbols.

  • Q : What is a Sub class Sub class : It is a

    Sub class: It is a class which extends its super class. The sub-class inherits all the members of its super class. All Java classes are the sub-classes of Object class, which is at the root of inheritance hierarchy.

  • Q : Definition of Role Normal 0 false false

    Normal 0 false false

  • Q : Non linear dynamic model equation to

    Could you please show the steps from non linear dynamic model equation to linear equation?

  • Q : What does WSDL stand for What does WSDL

    What does WSDL stand for?

  • Q : Define Class Class : It is a

    Class: It is a programming language concept which permits data and techniques to be grouped altogether. The class concept is basic to the notion of an object-oriented programming language. Methods of a class define the set of permitte

  • Q : Define Bounds Bounds : It is the limits

    Bounds: It is the limits of an array or collection. In Java, the lower limit is for all time zero (0). In case of an array, the upper bound is one less than the length of the array, and is fixed. Indexing exterior the bounds of an array or collection

  • Q : Reducing state space of code What is

    What is the way to reduce the state space of the code during model checking?

©TutorsGlobe All rights reserved 2022-2023.