- Joined
- Oct 16, 2007
- Messages
- 1,886
- Reaction score
- 11
- Points
- 0
- Location
- USA-WA
- Website
- www.orbiter-forum.com
So I am supposed to help my classmates if they get stuck on a report, but I kind-of got stuck myself.
So the report is;
and the necessary entities are;
So I am able to get the number of packages sold like;
...but then I am not sure on where to go from there. My book doesnot describe select subqueries that are inside select clauses. It only shows the where or having clauses. How can I take a multi-column result from a query and put it into the select clause, and better yet match it with the package ID?
So the report is;
# Report 6 - A summary of sales for any given day, categorized by Package type. (i.e., the total sales written on the specified day for each package type subscribed to by customers, not bills paid). This report should give details about each package type, the package price, the number of packages sold, and then the total sales amount for that package. Once again, remember that this is going to be a date driven report.
and the necessary entities are;
Code:
CREATE TABLE PACKAGE
(
PACK_ID NUMBER(5) NOT NULL,
PACK_DESC VARCHAR(64),
PACK_PRICE NUMBER(6,2) NOT NULL,
PACK_INC_DOC NUMBER(1),
PACK_INC_DOC2 NUMBER(1),
PACK_INC_LIFE NUMBER(1),
PACK_INC_LIFE2 NUMBER(1),
PACK_INC_MOVIE NUMBER(1),
PACK_INC_MOVIE2 NUMBER(1),
PACK_INC_NEWS NUMBER(1),
PACK_INC_NEWS2 NUMBER(1),
PACK_INC_SPORT NUMBER(1),
PACK_INC_SPORT2 NUMBER(1),
CONSTRAINT PACKAGE_PACK_ID_pk PRIMARY KEY (PACK_ID)
);
CREATE TABLE CUSTOMER
(
CUST_ID NUMBER(5) NOT NULL,
CUST_FNAME CHAR(32) NOT NULL,
CUST_LNAME CHAR(32) NOT NULL,
CUST_ADDRESS VARCHAR(64) NOT NULL,
CUST_ACC NUMBER(5) NOT NULL,
CUST_PHONE CHAR(10),
CUST_START DATE NOT NULL,
CUST_END DATE,
CUST_TERM NUMBER(1) NOT NULL,
CUST_TERM_RES VARCHAR(64),
CUST_KILLER_ID NUMBER(5),
PACK_CUST NUMBER(5) NOT NULL,
CONSTRAINT CUSTOMER_CUST_ID_pk PRIMARY KEY (CUST_ID),
CONSTRAINT CUSTOMER_PACK_CUST_fk FOREIGN KEY (PACK_CUST) REFERENCES PACKAGE(PACK_ID)
);
So I am able to get the number of packages sold like;
Code:
SELECT pack_cust AS “Package ID”, count(CUST_ID) AS “Number of Packages Sold”
FROM CUSTOMER
GROUP BY pack_cust
ORDER BY pack_cust;
...but then I am not sure on where to go from there. My book doesnot describe select subqueries that are inside select clauses. It only shows the where or having clauses. How can I take a multi-column result from a query and put it into the select clause, and better yet match it with the package ID?