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 Class scope Class scope :

    Class scope: Private variables stated outside the methods in a class contain class scope. They are available from all methods within a class, in spite of the order in which they are stated. The private methods too contain class scope. Variables and me

  • Q : What is an IP address IP address : An

    IP address: An Internet Protocol (abbreviated as IP) address for a networked computer. Presently, IP addresses comprises of 4-byte values, written in dotted decimal notation, like 129.12.0.1. In future, IP addresses will be 16-bytes long to accommodat

  • Q : Explain Hot spot Hot spot : This is an

    Hot spot: This is an area in an image map with a specific significance. A program usually monitors movements of the mouse, and reacts according to the actions related with the hot spots over which it passes. This may comprise displaying various status

  • Q : Define the term Instance Define the

    Define the term Instance: It is a synonym for object. The objects of a class are instantiated whenever a class constructor is invoked through the new operator.

  • Q : What is Bit Bit : It is a binary digit

    Bit: It is a binary digit that can take on two possible values: 0 and 1. The bits are basic building block of both data and programs. Computers regularly shift data around in multiples of eight-bit units (that is, bytes for the sake of effectiveness).

  • Q : Function of STR and LPSTR Explain what

     Explain what is the function of STR and LPSTR?

  • Q : What is First in-first out First in,

    First in, first out: It is FIFO semantics of the queue data structure. Items are eliminated in the order in which they arrived in the queue; therefore older items are always eliminated before newer ones.

  • Q : C programming assignment help S trings,

    Strings, Pointers, Arrays, Structures, and File I/O in C In this lab you will develop a few programs that will give you some practice with pointers, arrays, str

  • Q : Homework Assignment How much would it

    How much would it cost to do a basic program within the given requirements?

  • Q : Explain the term Web Services

    Explain the term Web Services Description Language.

©TutorsGlobe All rights reserved 2022-2023.