Queries for Customers of Art Course

The following questions refer to the Art Course database. You can obtain a copy of this data in the Access 2010 database, Art_Course_Database.accdb located on the course Canvas Web site.

The database contains data.

CUSTOMER (CustomerNumber, CustomerName, Phone)

COURSE (CourseNumber, Course, CourseDate, Fee)

ENROLLMENT (CustomerNumber, CourseNumber, AmountPaid)

where

CustomerNumber in ENROLLMENT must exist in CustomerNumber in CUSTOMER

CourseNumber in ENROLLMENT must exist in CourseNumber in COURSE 

Write SQL queries to produce the following results:

1)  List all students and courses they are registered for. Include, in this order, CustomerNumber, CustomerName, Phone, CourseNumber, and AmountPaid.

2) List the total amount paid for each course starting after July 4, 2009. Include, in this order, CourseNumber, CourseName, and total amount paid for that course.

3) List the average amount paid for each customer. Include, in this order, CustomerName and average amount paid by that customer.

4) List all students registered in the Adv. Pastels starting on October 1, 2009. Include, in this order, CourseName, CourseDate, Fee, CustomerName, and Phone.

Solution 

Question 1:

SELECT CUSTOMER.CustomerNumber AS CUSTOMER_CustomerNumber, CUSTOMER.CustomerLastName, CUSTOMER.CustomerFirstName, CUSTOMER.Phone,COURSE.CourseNumber AS COURSE_CourseNumber,  ENROLLMENT.AmountPaid

FROM CUSTOMER INNER JOIN (COURSE INNER JOIN ENROLLMENT ON COURSE.[CourseNumber] = ENROLLMENT.[CourseNumber]) ON CUSTOMER.[CustomerNumber] = ENROLLMENT.[CustomerNumber];

Question 2:

SELECT COURSE.CourseNumber AS COURSE_CourseNumber, COURSE.Course AS COURSE_CourseName, ENROLLMENT.AmountPaid

FROM COURSE INNER JOIN ENROLLMENT ON COURSE.[CourseNumber] = ENROLLMENT.[CourseNumber] WHERE  DateValue(COURSE.CourseDate)>DateValue(’04-07-09′);

Question 3:

SELECT AVG(ENROLLMENT.AmountPaid) AS AverageAmountPaid,CUSTOMER.CustomerFirstName,CUSTOMER.CustomerLastName  FROM ENROLLMENT INNER JOIN CUSTOMER ON ENROLLMENT.[CustomerNumber] = CUSTOMER.[CustomerNumber] GROUP BY CUSTOMER.CustomerNumber,CUSTOMER.CustomerFirstName,CUSTOMER.CustomerLastName;

Question 4:

SELECT COURSE.Course,COURSE.CourseDate,COURSE.Fee, CUSTOMER.CustomerFirstName, CUSTOMER.CustomerLastName, CUSTOMER.Phone

FROM CUSTOMER INNER JOIN (COURSE INNER JOIN ENROLLMENT ON COURSE.[CourseNumber] = ENROLLMENT.[CourseNumber]) ON CUSTOMER.[CustomerNumber] = ENROLLMENT.[CustomerNumber] WHERE COURSE.Course=’Adv Pastels’ AND DateValue(COURSE.CourseDate)=DateValue(’01-10-09′);