SQL Databases, asgmt III

May 20, 2018 | Author: Madeleine Sangoi | Category: Information Retrieval, Data, Information Technology Management, Computer Data, Data Management


Comments



Description

Madeleine Sangoi#300851594 Assignment#3 ______________________________________________________________________________________________ The bb_department table lists the two main business areas in the company (coffee sales and equipment sales); bb_product table contains information on all products, such as name, description, price, sales pricing, etc. Three tables are used to manage product options. Table bb_productoptioncategory records main categories for products (i.e., size and form); table bb_productoptiondetails stores the choices in each category, e.g., whole bean or ground for form; and table bb_productoption links each product to its applicable options. Each product can be associated with many options. Table bb_shopper is to store customers’ information. When a customer begins shopping, a new basket is created in the bb_basket. As the shopper selects items, the selected items are inserted in the bb_basketitem table. Table bb_basketstatus stores data related to order status. Possible statuses include order placed, order verified, and sent to shipping, order shipped, order cancelled, order on back-order. The other tables associated with completing an order include bb_tax and bb_shipping. The company currently calculates shipping cost based on the quantity of items ordered. Q1. Produce an unduplicated list of all product IDs for all products that have been sold[2 marks] SELECT DISTINCT IDPRODUCT FROM bb_product join bb_basketitem using(IDProduct) WHERE quantity > 0; Madeleine Sangoi # 300851594 Assignment 3 Q2. List the basked ID, product ID, and description for all items ordered[2 marks] SELECT IDBasket, IDProduct FROM bb_Product JOIN bb_Basketitem using (IDProduct) JOIN bb_Basket USING (IDBAsket) WHERE ORDERPLACED >=1; Madeleine Sangoi # 300851594 Assignment 3 Q3. List all orders (basket ID, shopper ID, and date ordered) placed in February 2012[2 marks] SELECT DISTINCT IDBASKET, IDSHOPPER, DTORDERED FROM BB_BASketItem JOIN BB_Basket USING(IDBASKET) JOIN BB_SHOPPER USING(IDSHOPPER) WHERE DTORDERED BETWEEN '12-02-01' AND '12-02-28'; Q4. List all active coffee products (product ID, name and price) for all coffee items priced above the overall average of coffee items[2 marks] SELECT IDPRODUCT, PRODUCTNAME, to_char(PRICE,'$999.99') FROM BB_PRODUCT WHERE price>(SELECT AVG(PRICE) FROM BB_Product); Madeleine Sangoi # 300851594 Assignment 3 Q5. Implement a PL/SQL block to determine whether a customer is rated high, mid or low based on his or her total purchase. If the total purchases are greater than $200, then the customer rated to be high, mid if greater than $100, and low if $100 or lower[5 marks] DECLARE lv_rate bb_basket.total%TYPE; lv_shopper_num bb_basket.idshopper%TYPE; BEGIN SELECT IDSHOPPER, TOTAL INTO lv_shopper_num, lv_rate FROM bb_Basket; IF lv_rate > 200 THEN DBMS_OUTPUT.PUT_LINE('Rate is hight'); ELSE IF lv_rate > 100 THEN DBMS_OUTPUT.PUT_LINE('Rate is MEDIUM'); ELSE IF lv_rate < 100 THEN DBMS_OUTPUT.PUT_LINE('Rate is LOW'); ELSE DBMS_OUTPUT.PUT_LINE('Rate is not Valid'); END IF; END; Q6. The shipping cost is based on the number of items ordered and club membership status. The applicable rates are shown in the following chart. Implement a PL/SQL block to determine the shipping cost. [7 marks] Quantity of items NonMember Shipping cost Member shipping cost Up to 3 $5.00 $3.00 4-6 $7.5 $5 7-10 $10 $7 More than 10 $12 $9 Madeleine Sangoi # 300851594 Assignment 3 DECLARE lv_quantity bb_basket.quantity%TYPE; lv_total_fee bb_shipping.fee%TYPE; BEGIN SELECT fee, quantity INTO lv_total_fee, lv_quantity FROM bb_basket, shipping; IF lv_quantity < 3 THEN lv_total_fee := 3.00; ELSE IF lv_quantity < 7 THEN lv_total_fee := 5.00; ELSE IF lv_quantity < 10 THEN lv_total_fee := 7.00; ELSE IF lv_quantity > 10 THEN lv_total_fee := 9.00; END IF; DBMS_OUTPUT.PUT_LINE('quantity ' || lv_quantity || 'Shippingcost ' || lv_total_fee ); END;
Copyright © 2024 DOKUMEN.SITE Inc.