wukles
2012-11-14 23:56:09 UTC
The key tables in the schema include
a) Customers: This table has customer level details.
b) Employees: This table has details on employees working at the store.
c) Suppliers: This table has details on the suppliers restocking products at the store.
d) Orders: This table has details on the various orders made.
e) Addresses: data on the various addresses for customers and employees.
f) Products: This has product level details.
g) Order_items: Listing the number of items of each product in an order. An order will include multiple products and 1 or more units of each product in the order. Hence number of items is =quantity of product 1+quantify of product 2+quantify of product 3 etc.
h) Deliveries: This table has details on deliveries against orders made.
i) Customer_Addresses: This table has address details of all customers.
Total value of an order= price of product 1* quantity of product 1+ price of product 2* quantity of product 2+ price of product 3* quantity of product 3 etc.
By using the above tables, write an SQL statement to list the order(s) that have been kept outstanding for the maximum duration of time.
Write an SQL statement to list the order(s) that have been kept outstanding for the maximum duration of time.
Note 1: The name of the column must be order_id
Note 2: While writing SQL query, you are required to write the table name as schemaname.tablename (For example Retail_Store.Orders where Retail_Store is schemaname and Orders is tablename).
My Answer is
select distinct Addresses.address_ID, Addresses.line_1, Addresses.line_2, Addresses.city, Addresses.state, Addresses.zip_code from Supplier.Addresses where Addresses.address_ID in (select Supplier_addresses.address_Id from Supplier.Supplier_Addresses where Supplier_addresses.address_type_code in (select Ref_address_types.address_type_code from Supplier.Ref_address_types))
Is this correct ???