18. Orders Table - Build in
Здравейте, относно задача как да се добави и селектират новите колони с Pay Due /Deliver Due? Коя функция се изполва на Date.
Задачата е :
You are given a table Orders(Id, ProductName, OrderDate) filled with data. Consider that the payment for that order must be accomplished within 3 days after the order date. Also the delivery date is up to 1 month. Write a query to show each product’s name, order date, pay and deliver due dates.
Original Table
|
Id |
ProductName |
OrderDate |
|
1 |
Butter |
2016-09-19 00:00:00.000 |
|
2 |
Milk |
2016-09-30 00:00:00.000 |
|
3 |
Cheese |
2016-09-04 00:00:00.000 |
|
4 |
Bread |
2015-12-20 00:00:00.000 |
|
5 |
Tomatoes |
2015-12-30 00:00:00.000 |
|
… |
… |
… |
Output
|
ProductName |
OrderDate |
Pay Due |
Deliver Due |
|
Butter |
2016-09-19 00:00:00.000 |
2016-09-22 00:00:00.000 |
2016-10-19 00:00:00.000 |
|
Milk |
2016-09-30 00:00:00.000 |
2016-10-03 00:00:00.000 |
2016-10-30 00:00:00.000 |
|
Cheese |
2016-09-04 00:00:00.000 |
2016-09-07 00:00:00.000 |
2016-10-04 00:00:00.000 |
|
Bread |
2015-12-20 00:00:00.000 |
2015-12-23 00:00:00.000 |
2016-01-20 00:00:00.000 |
|
Tomatoes |
2015-12-30 00:00:00.000 |
2016-01-02 00:00:00.000 |
2016-01-30 00:00:00.000 |
|
… |
… |
… |
… |
Oще веднъж голямо благодаря :)
SELECT product_name, order_date, DATE_ADD(order_date, INTERVAL 3 DAY) AS pay_due, DATE_ADD(order_date, INTERVAL 1 MONTH) AS deliver_due FROM orders;