0

These are the tables I have to work with.

customer (cust_id, name, city, postcode)

order (order_id, cust_id, date)

orderline (order_id, video_id, quantity)

video (video_id, description, price, category_id)

category (category_id, description)

I need to:

Create a view named CustomerSummary which shows the customer name along with the total number of videos ordered and total order value for each customer.

4
  • 4
    What've u tried so far? At least, show your effort.... Commented May 12, 2013 at 10:03
  • postgresql.org/docs/9.2/static/sql-createview.html Commented May 12, 2013 at 10:04
  • do you have any auto increment columns? Commented May 12, 2013 at 10:05
  • 2
    order is a reserved word. Don't use it as an identifier, even if it appears to work. Commented May 12, 2013 at 10:06

1 Answer 1

1

you have to join three tables for required output as below -

    SELECT c.Cust_Id,
         c.NAME,
         COUNT(DISTINCT o.Order_Id) Num_Of_Order,
         COUNT(*) Num_Of_Video
    FROM Customer c, Order_Table o, Orderline Ol
   WHERE c.Cust_Id = o.Cust_Id
     AND o.Order_Id = Ol.Order_Id
   GROUP BY c.Cust_Id, c.NAME

now for this query you need to create view - Just add Create or Replace View CustomerSummary as before this query to create view with name CustomerSummary

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.