1

使用 SQL Plus

需要以下方面的帮助: 任何给定日期的销售额摘要,按包裹类型分类(即,客户订阅的每个包裹在指定日期的总销售额,而不是支付的账单)。该报告应提供有关每种包裹类型、包裹价格、已售包裹数量以及该包裹的总销售额的详细信息。再一次记住,这将是一个日期驱动的报告。

SET ECHO ON

SPOOL C:\CIS336\InfoMiners\Week7\Final\InfoMiners_Week7_Task5_FinalSpool.txt

SET LINESIZE 120
SET PAGESIZE 45
SET FEEDBACK 1

-- CIS-336 Online
-- XXXXX XXXXX
-- InfoMiners Week 7 - Task 5 - Reports
-- april 15, 2012


-- DROP Table Statements

DROP TABLE package_guide CASCADE CONSTRAINTS PURGE;
DROP TABLE employee CASCADE CONSTRAINTS PURGE;
DROP TABLE customer CASCADE CONSTRAINTS PURGE;
DROP TABLE cust_survey CASCADE CONSTRAINTS PURGE;
DROP TABLE bill_info CASCADE CONSTRAINTS PURGE;
DROP TABLE package CASCADE CONSTRAINTS PURGE;
DROP TABLE channel CASCADE CONSTRAINTS PURGE;
DROP TABLE program CASCADE CONSTRAINTS PURGE;
DROP TABLE ratings CASCADE CONSTRAINTS PURGE;
DROP TABLE network_supplier CASCADE CONSTRAINTS PURGE;


-- CREATE Table Statements

CREATE TABLE network_supplier
(
supplier_id VARCHAR2(15) CONSTRAINT pk_supplier_id PRIMARY KEY,
supplier_name VARCHAR2(15) NOT NULL,
address VARCHAR2(25) NOT NULL,
city VARCHAR2(17) NOT NULL,
state CHAR(2) NOT NULL,
zip_code NUMBER(5) NOT NULL,
contact_name VARCHAR2(20) NOT NULL,
contact_phone VARCHAR2(14) NOT NULL
);

CREATE TABLE ratings
(
rating_code VARCHAR2(17) CONSTRAINT pk_rating_code PRIMARY KEY,
rating_description VARCHAR2(70)
);

CREATE TABLE program
(
program_id NUMBER(17) CONSTRAINT pk_program_id PRIMARY KEY,
name VARCHAR2(70) NOT NULL,
supplier_id VARCHAR2(15) REFERENCES network_supplier(supplier_id),
length NUMBER(5) NOT NULL,
description VARCHAR2(30),
type VARCHAR2 (15) NOT NULL,
rating_code VARCHAR2(17) REFERENCES ratings(rating_code)
);

CREATE TABLE channel
(
channel_id VARCHAR2(20) CONSTRAINT pk_channel_id PRIMARY KEY,
ch_number NUMBER(2) NOT NULL,
name VARCHAR2(20) NOT NULL,
type VARCHAR2(20) NOT NULL,
customer_count NUMBER(30) NOT NULL,
supplier_id VARCHAR2(15) REFERENCES network_supplier(supplier_id),
show_time TIMESTAMP NOT NULL
);

CREATE TABLE package
(
package_id VARCHAR2(2) CONSTRAINT pk_package_id PRIMARY KEY,
name VARCHAR2(25) NOT NULL,
cost NUMBER(5) NOT NULL
);

CREATE TABLE bill_info
(
acct_num NUMBER(10) CONSTRAINT pk_acct_num PRIMARY KEY,
balance NUMBER(5) NOT NULL,
due_date DATE NOT NULL,
acct_current NUMBER(1),
package_id VARCHAR2(2) REFERENCES package(package_id)
);

CREATE TABLE cust_survey
(
survey_id VARCHAR2(20) CONSTRAINT pk_survey_id PRIMARY KEY,
fav_channel VARCHAR2(20) NOT NULL,
months_paid NUMBER(3) NOT NULL
);

CREATE TABLE customer
(
customer_id NUMBER(10) CONSTRAINT pk_customer_id PRIMARY KEY,
active_date DATE NOT NULL,
cancel_date DATE,
cancel_reason NUMBER(1),
first_name VARCHAR2(10) NOT NULL,
last_name VARCHAR2(10) NOT NULL,
address VARCHAR2(25) NOT NULL,
city VARCHAR2(15) NOT NULL,
state CHAR(2) NOT NULL,
zip_code NUMBER(5) NOT NULL,
phone_num NUMBER(10) NOT NULL,
acct_num NUMBER(10) REFERENCES bill_info(acct_num) NOT NULL,
survey_id VARCHAR2(20) REFERENCES cust_survey(survey_id) NOT NULL,
package_id VARCHAR2(2) REFERENCES package(package_id) NOT NULL,
email VARCHAR(20) NOT NULL
);

CREATE TABLE employee
(
emp_num NUMBER(11) CONSTRAINT pk_emp_num PRIMARY KEY,
first_name VARCHAR2(10) NOT NULL,
last_name VARCHAR2(10) NOT NULL,
emp_phone NUMBER(10) NOT NULL
);

CREATE TABLE package_guide
(
package_id REFERENCES package(package_id) NOT NULL,
channel_id REFERENCES channel(channel_id) NOT NULL,
program_id REFERENCES program(program_id) NOT NULL
);


-- INSERT Statements

-- Data for network_supplier Table (4 Records)

INSERT INTO network_supplier (supplier_id, supplier_name, address, city, state, zip_code, contact_name, contact_phone)
VALUES (1, 'NBC', '10880 Wilshire Blvd #1200', 'Los Angeles', 'CA', 90057, 'XXXXX XXXXX', '(XXX) XXX-XXXX' );

INSERT INTO network_supplier (supplier_id, supplier_name, address, city, state, zip_code, contact_name, contact_phone)
VALUES (2, 'ABC', '111 Hollywood Blvd.', 'Los Angeles', 'CA', 90046, 'Jack Carverisi', '(XXX) XXX-XXXX' );

INSERT INTO network_supplier (supplier_id, supplier_name, address, city, state, zip_code, contact_name, contact_phone)
VALUES (3, 'FOX', '10960 Wilshire Blvd', 'Los Angeles', 'CA', 90057, 'Janis Carmikel', '(XXX) XXX-XXXX' );

INSERT INTO network_supplier (supplier_id, supplier_name, address, city, state, zip_code, contact_name, contact_phone)
VALUES (4, 'WARNER', '3701 W Oak St.', 'Burbank', 'CA', 91501, 'Simon Philips', '(XXX) XXX-XXXX' );


-- Data for ratings Table (7 Records)

INSERT INTO ratings (rating_code, rating_description)
VALUES ('TV-Y', 'All Children');

INSERT INTO ratings
VALUES ('TV-Y7', 'Directed to Older Children');

INSERT INTO ratings
VALUES ('TV-Y7-FV', 'Directed to Older Children - Fantasy Viol

已经尝试过:select 语句的不同变体,但我不明白使用子查询来完全使 select 语句工作。

阅读更多:SQL Plus 作业问题 - JustAnswer http://www.justanswer.com/computer-programming/6j1qs-sql-plus-homework-question.html#ixzz1sA4U5tTz

4

0 回答 0