Homework Solution: I have posted this once but it is a little more complicated than it looks at first. It is asking for the delay in weeks and a…

    Sales.Orders Columns Sales.Customers orderid (PK, int, not nul) custid (FK, int, null) Columns custid (PK, int, not null) f empid (FK, int, not nul) companyname (nvarchar(40), not null) orderdate (datetime, not null) requireddate (datetime, not null) shippeddate (datetime, null) shipperid (FK, int, not null) freight (money, not null) 目contactname (nvarchar(30), not null) - contacttitle (nvarchar(30), not null) Sales.OrderDetails address (nvarchar(60), not null) city (nvarchar(15), not null) Columns ? orderid (PK, FK, int, not null) productid (PK, FK, int, not null) 目region (nvarchar(15), null) unitprice (money, not null) qty (smallint, not null) discount (numeric(4,3), not null) 目shipname (nvarchar(40), not null) postalcode (nvarchar(10), null) country (nvarchar(15), not null) shipaddress (nvarchar(60), not null) 目shipcity (nvarchar(15), not null) 目shipregion (nvarchar(15), null) 目shippostalcode (nvarchar(10), null) 目phone (nvarchar(24), not null) fax (nvarchar(24), null) shipcountry (nvarchar(15), not null) The customer ID and company name and the longest delay in shipping on any order to that customer Express the delay in weeks and place the output in ascending order by the delay I have posted this once but it is a little more complicated than it looks at first. It is asking for the delay in weeks and also for just the longest delay per Customer ID not every delay out there. I can figure out how to get the delay in weeks using the CAST function but I can't figure out how to get the MAX per customer when CAST is used to get the delay in weeks
    Sales.Orders Columns Sales.Customers orderid (PK, int, not nul) custid (FK, int, null) Columns custid (PK, int, not null) f empid (FK, int, not nul) companyname (nvarchar(40), not null) orderdate (datetime, not null) requireddate (datetime, not null) shippeddate (datetime, null) shipperid (FK, int, not null) freight (money, not null) 目contactname (nvarchar(30), not null) - contacttitle (nvarchar(30), not null) Sales.OrderDetails address (nvarchar(60), not null) city (nvarchar(15), not null) Columns ? orderid (PK, FK, int, not null) productid (PK, FK, int, not null) 目region (nvarchar(15), null) unitprice (money, not null) qty (smallint, not null) discount (numeric(4,3), not null) 目shipname (nvarchar(40), not null) postalcode (nvarchar(10), null) country (nvarchar(15), not null) shipaddress (nvarchar(60), not null) 目shipcity (nvarchar(15), not null) 目shipregion (nvarchar(15), null) 目shippostalcode (nvarchar(10), null) 目phone (nvarchar(24), not null) fax (nvarchar(24), null) shipcountry (nvarchar(15), not null) The customer ID and company name and the longest delay in shipping on any order to that customer Express the delay in weeks and place the output in ascending order by the delay

    Expert Answer

     
    As we need to get longest delay in shipping and query should return the delay in ascending order.

    Sales.Orders Columns Sales.Customers regulateid (PK, int, referable nul) custid (FK, int, trifling) Columns custid (PK, int, referable trifling) f empid (FK, int, referable nul) troopcall (nvarchar(40), referable trifling) regulatedate (datetime, referable trifling) requireddate (datetime, referable trifling) shippeddate (datetime, trifling) shipperid (FK, int, referable trifling) burden (money, referable trifling) 目contactcall (nvarchar(30), referable trifling) - contacttitle (nvarchar(30), referable trifling) Sales.OrderDetails harangue (nvarchar(60), referable trifling) city (nvarchar(15), referable trifling) Columns ? regulateid (PK, FK, int, referable trifling) productid (PK, FK, int, referable trifling) 目region (nvarchar(15), trifling) unitprice (money, referable trifling) qty (smallint, referable trifling) abatement (numeric(4,3), referable trifling) 目shipcall (nvarchar(40), referable trifling) postalcode (nvarchar(10), trifling) empire (nvarchar(15), referable trifling) shipharangue (nvarchar(60), referable trifling) 目shipcity (nvarchar(15), referable trifling) 目shipregion (nvarchar(15), trifling) 目shippostalcode (nvarchar(10), trifling) 目phone (nvarchar(24), referable trifling) fax (nvarchar(24), trifling) shipempire (nvarchar(15), referable trifling) The customer ID and troop call and the longest relapse in shipping on any regulate to that customer Express the relapse in weeks and assign the extinguishedput in ascending regulate by the relapse

    I feel posted this uniformly excepting it is a petty further confused than it looks at leading. It is scrutiny ce the relapse in weeks and so ce equitable the longest relapse per Customer ID referable perfect relapse extinguished there. I can aspect extinguished how to procure the relapse in weeks using the CAST character excepting I can’t aspect extinguished how to procure the MAX per customer when CAST is used to procure the relapse in weeks

    Sales.Orders Columns Sales.Customers regulateid (PK, int, referable nul) custid (FK, int, trifling) Columns custid (PK, int, referable trifling) f empid (FK, int, referable nul) troopcall (nvarchar(40), referable trifling) regulatedate (datetime, referable trifling) requireddate (datetime, referable trifling) shippeddate (datetime, trifling) shipperid (FK, int, referable trifling) burden (money, referable trifling) 目contactcall (nvarchar(30), referable trifling) – contacttitle (nvarchar(30), referable trifling) Sales.OrderDetails harangue (nvarchar(60), referable trifling) city (nvarchar(15), referable trifling) Columns ? regulateid (PK, FK, int, referable trifling) productid (PK, FK, int, referable trifling) 目region (nvarchar(15), trifling) unitprice (money, referable trifling) qty (smallint, referable trifling) abatement (numeric(4,3), referable trifling) 目shipcall (nvarchar(40), referable trifling) postalcode (nvarchar(10), trifling) empire (nvarchar(15), referable trifling) shipharangue (nvarchar(60), referable trifling) 目shipcity (nvarchar(15), referable trifling) 目shipregion (nvarchar(15), trifling) 目shippostalcode (nvarchar(10), trifling) 目phone (nvarchar(24), referable trifling) fax (nvarchar(24), trifling) shipempire (nvarchar(15), referable trifling) The customer ID and troop call and the longest relapse in shipping on any regulate to that customer Express the relapse in weeks and assign the extinguishedput in ascending regulate by the relapse

    Expert Vindication

     

    As we want to procure longest relapse in shipping and interrogation should repay the relapse in ascending regulate.

    Select sc.custid, sc.companyname

    (so.shippeddate – so.requireddate)/7 relapse

    From sales.Regulate so, sales.Customers sc

    Where so.custid =sc.custid

    Regulate by relapse

    It succeed grant facts as regulate by of relapse and relapse comes in cem of weeks