2. Write a query that returns a result set containing the details of the first order placed based on the order date. The
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
2. Write a query that returns a result set containing the details of the first order placed based on the order date. The
Same thing for this questions:
For the prompt above, What is my code missing from below?
2. Write a query that returns a result set containing the details of the first order placed based on the order date. The result set should include order ID, order date, order total, line-item ID, product ID, product name, unit price, and quantity. There should be one row for each line-item. Sort the result-set by line-item ID, ascending. ORDER_ID 2418 ORDER_DATE 20-MAR-84 84.18.21.862632 PM ORDER_TOTAL 5546.6 LINE_ITEM_ID PRODUCT_ID 1 3882 PRODUCT_NAME Modem 56/90/E UNIT_PRICE QUANTITY 75 15
1 SELECT oe.orders.order_id, 2 3 4 5 6 7 8 FROM oe.customers 9 INNER JOIN oe.orders 10 ON oe.customers.customer_id = oe.orders.customer_id 11 INNER JOIN oe.order_items 12 ON oe.orders.order_id = oe.order_items.order_id 13 INNER JOIN 14 (SELECT oe.order_items.order_id, 15 COUNT(order_items.line_item_id) AS line_item_count 16 FROM oe.order_items 17 group by order id 18 ) lineItemCount ORDER_ID 19 ON oe.order_items.order_id = lineItemCount.order_id 20 ORDER BY oe.customers.customer_id, oe.orders.order_date, oe.orders.order_id, oe.order_items.line_item_id 2458 2458 oe.orders.order_date, oe.orders.order_total, 2458 oe.order_items.line_item_id, oe.order_items.product_id, oe.order_items.unit_price, oe.order_items.quantity 2458 2458 ORDER_DATE 16-AUG-07 03.34.12.234359 PM 16-AUG-07 03.34.12.234359 PM 16-AUG-07 03.34.12.234359 PM 16-AUG-07 03.34.12.234359 PM ORDER_TOTAL LINE_ITEM_ID PRODUCT_ID UNIT_PRICE QUANTITY 78279.6 78279.6 78279.6 78279.6 16-AUG-07 03.34.12.234359 PM 78279.6 1 2 3 4 5 3117 3123 3127 3134 3143 38 79 488.4 17 15 140 112 114 115 129
5. Write a query that returns a result set containing the customer ID, order ID, and order date for each customer's first and last order. If a customer has only made one order, then there should only be one row for the customer, otherwise two rows. Assign the same integer value to ties in order date. Use consecutive integers (e.g., 1, 1, 2, 3, 4, 4, 5). Alias any derived columns as you see fit. Sort the result set by customer ID, ascending. ITSS 4300 Assessment 3A CUSTOMER_ID ORDER_ID 101 101 102 102 2458 2447 2431 2397 ORDER_DATE 16-AUG-07 03.34.12.234359 PM ORDER_DATE_SEQUENCE_ASC 1 27-JUL-08 08.59.10.223344 AM 4 14-SEP-06 07.03.04.763452 AM 1 19-NOV-07 02.41.54.696211 PM 4 ORDER_DATE_SEQUENCE_DESC 4 1 4 1
SQL Worksheet 1 SELECT oe.orders.customer_id, 2 3 4 5 6 7 FROM oe.orders 8 ORDER BY oe.orders.customer_id, oe.orders.order_date ASC, 9 10 101 101 CUSTOMER_ID 101 101 102 oe.orders.order_id, oe.orders.order_date, oe.orders.order_total, 102 ROW_NUMBER() OVER (PARTITION BY oe.orders.customer_id ORDER BY oe.orders.customer_id ASC) AS order_date_sequence_DESC 192 oe.orders.customer_id, oe.orders.order_date DESC; ORDER_ID 2458 2430 2413 2447 2431 2414 2422 ORDER_DATE 16-AUG-07 03.34.12.234359 PM 02-OCT-07 06.18.36.663332 AM 29-MAR-08 01.34.04.525934 PM 27-JUL-08 08.59.10.223344 AM 14-SEP-06 07.03.04.763452 AM 29-MAR-07 02.22.40.536996 PM 14 SEP 07 09 52 48 222245 AN AM ORDER_TOTAL 78279.6 29669.9 48552 33893.6 5610.6 10794.6 10572 ORDER_DATE_SEQUENCE_DESC 1 2 3 4 1 2 Clear Find