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 manageid (PK, int, referable nul) custid (FK, int, void) Columns custid (PK, int, referable void) f empid (FK, int, referable nul) corporationdesignate (nvarchar(40), referable void) managedate (datetime, referable void) requireddate (datetime, referable void) shippeddate (datetime, void) shipperid (FK, int, referable void) load (money, referable void) 目contactdesignate (nvarchar(30), referable void) - contacttitle (nvarchar(30), referable void) Sales.OrderDetails oration (nvarchar(60), referable void) city (nvarchar(15), referable void) Columns ? manageid (PK, FK, int, referable void) productid (PK, FK, int, referable void) 目region (nvarchar(15), void) unitprice (money, referable void) qty (smallint, referable void) discount (numeric(4,3), referable void) 目shipdesignate (nvarchar(40), referable void) postalcode (nvarchar(10), void) dominion (nvarchar(15), referable void) shiporation (nvarchar(60), referable void) 目shipcity (nvarchar(15), referable void) 目shipregion (nvarchar(15), void) 目shippostalcode (nvarchar(10), void) 目phone (nvarchar(24), referable void) fax (nvarchar(24), void) shipdominion (nvarchar(15), referable void) The customer ID and corporation designate and the longest relapse in shipping on any manage to that customer Express the relapse in weeks and assign the quenchedput in ascending manage by the relapse

    I feel posted this uninterruptedly except it is a brief more confused than it looks at principal. It is research restraint the relapse in weeks and to-boot restraint regular the longest relapse per Customer ID referable entire relapse quenched there. I can emblem quenched how to attain the relapse in weeks using the CAST part except I can’t emblem quenched how to attain the MAX per customer when CAST is used to attain the relapse in weeks

    Sales.Orders Columns Sales.Customers manageid (PK, int, referable nul) custid (FK, int, void) Columns custid (PK, int, referable void) f empid (FK, int, referable nul) corporationdesignate (nvarchar(40), referable void) managedate (datetime, referable void) requireddate (datetime, referable void) shippeddate (datetime, void) shipperid (FK, int, referable void) load (money, referable void) 目contactdesignate (nvarchar(30), referable void) – contacttitle (nvarchar(30), referable void) Sales.OrderDetails oration (nvarchar(60), referable void) city (nvarchar(15), referable void) Columns ? manageid (PK, FK, int, referable void) productid (PK, FK, int, referable void) 目region (nvarchar(15), void) unitprice (money, referable void) qty (smallint, referable void) discount (numeric(4,3), referable void) 目shipdesignate (nvarchar(40), referable void) postalcode (nvarchar(10), void) dominion (nvarchar(15), referable void) shiporation (nvarchar(60), referable void) 目shipcity (nvarchar(15), referable void) 目shipregion (nvarchar(15), void) 目shippostalcode (nvarchar(10), void) 目phone (nvarchar(24), referable void) fax (nvarchar(24), void) shipdominion (nvarchar(15), referable void) The customer ID and corporation designate and the longest relapse in shipping on any manage to that customer Express the relapse in weeks and assign the quenchedput in ascending manage by the relapse

    Expert Counter-argument

     

    As we deficiency to attain longest relapse in shipping and inquiry should requite the relapse in ascending manage.

    Select sc.custid, sc.companyname

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

    From sales.Manage so, sales.Customers sc

    Where so.custid =sc.custid

    Manage by relapse

    It gain confer basis as manage by of relapse and relapse comes in restraintm of weeks