Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

SQL homework

Please help me with this homework

206 10 (Optional, Advanced)
207 -- Write a query that returns for each order the number of days that past
208
since the same customer's previous order. To determine recency among orders,
use orderdate as the primary sort element and orderid as the tiebreaker.
210 -- Tables involved: TSQLV4 database, Sales.Orders table
209
--
--
211
212 -- Desired output:
213 custid
214
215 1
216 1
217 1
218 1
219 1
220 1
221 2
222 2
223 2
224 2
225...
orderdate orderid
2015-08-25 10643
2015-10-03 10692
2015-10-13 10702
2016-01-15 10835
2016-03-16 10952
2016-04-09 11011
2014-09-18 10308
2015-08-08 10625
2015-11-28 10759
2016-03-04 10926
226
227 (830 row(s) affected)
diff
NULL
39
10
94
61
24
NULL
324
112
97
expand button
Transcribed Image Text:206 10 (Optional, Advanced) 207 -- Write a query that returns for each order the number of days that past 208 since the same customer's previous order. To determine recency among orders, use orderdate as the primary sort element and orderid as the tiebreaker. 210 -- Tables involved: TSQLV4 database, Sales.Orders table 209 -- -- 211 212 -- Desired output: 213 custid 214 215 1 216 1 217 1 218 1 219 1 220 1 221 2 222 2 223 2 224 2 225... orderdate orderid 2015-08-25 10643 2015-10-03 10692 2015-10-13 10702 2016-01-15 10835 2016-03-16 10952 2016-04-09 11011 2014-09-18 10308 2015-08-08 10625 2015-11-28 10759 2016-03-04 10926 226 227 (830 row(s) affected) diff NULL 39 10 94 61 24 NULL 324 112 97
Expert Solution
Check Mark
Step 1: Outline of the given question

The question asks for an SQL query that calculates the number of days that have passed since the previous order for each customer, using the order date as the primary sorting criterion and the order ID as a tiebreaker. The goal is to determine the recency of orders among customers.

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education