Question:
Write an SQL statement to list the order(s) that have been kept outstanding for the maximum duration of time?
wukles
2012-11-14 23:56:09 UTC
A retail store stocks multiple products inclusive of food, furniture, electronics and pet products and provides home delivery services against orders. The delivery is handled by its employees. The store has details stored on customers and tracks their orders, its employees who deliver products against these orders and suppliers who restock the products.

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 ???
Three answers:
TheMadProfessor
2012-11-15 11:18:26 UTC
Did you simply copy that query from one of your other questions, because it isn't even in the ballpark...
guberman
2016-10-24 15:21:09 UTC
it truly is a results of the field beinga textual content field and having different textual content in it. you may style numbers interior the numeric format yet when you're wokring with textual content you both style them in textual order (a million, 11, 12, 13, 2, 21, 22....) or you should use a conversion to numeric in the course of the elect. because you've both textual content and numbers interior the field the latter step ought to fail even as it hits the textual content.
Raviraj
2012-11-15 06:39:52 UTC
i didnt get you exactly what you are asking???

do you want to get order_id s in the decreasing order of the time of delivery..???


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...