Question: I need help with a SQL query for the days it takes to ship an order that can be matched to an individual sales rep.
I need help with a SQL query for the days it takes to ship an order that can be matched to an individual sales rep. Example if the order date was 2/17/2019 and the invoice date was 2/19/2019 it took 2 days to complete and ship the order.
The output wold look like the following

Some things I got so far.
I believe in order to get the date between the orders this should do the trick. DATEFDIFF("d" , [order table]. date created , [invoice table].invoice date) As turnaround
I also can use MAX([invoice table]. sales rep) AS Rep_ID to count each order a sales rep is placed on.
The tables im joining will include, customer, orders, invoice. The customer's table joins invoice and orders based customer ID and orders and invoice link on order #.
sales_rep ID is a value in customer, orders, invoice
I'm geting stuck on how to group everything
Thank you
Edit: I'm not sure how I would provide a structure for my database. If you could provide a setup of how you would go about this using your own data. So more info. I need the query to count the days between when the order was created to when its shipped and based on the column of 1's, 2's, 3's and 4+, count how many times the number appears and give a result like the table above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
