Friday, March 16, 2012

"Tracking"

OK. For DDL, please refer to the classical Northwind ORDERS table,
problem/challenge, find the longest duration (start_date and
end_date), during which, no orders were placed.

FYI, column names by the order of colid per syscolumns:
OrderID
CustomerID
EmployeeID
OrderDate
RequiredDate
ShippedDate
ShipVia
Freight
ShipName
ShipAddress
ShipCity
ShipRegion
ShipPostalCode
ShipCountry

Any idea/approach? TIA.Does this help?

select o1.OrderDate, o2.OrderDate, DATEDIFF( day, o1.OrderDate,
o2.OrderDate) as days_between
from dbo.Orders o1, dbo.Orders o2
where o1.OrderDate < o2.OrderDate
and not exists
(select * from dbo.Orders o3
where o3.OrderDate < o2.OrderDate
and o1.OrderDate < o3.OrderDate)
group by o1.OrderDate, o2.OrderDate
order by days_between desc

"DonLi" <donli@.yahoo.com> wrote in message
news:9a172893.0404051228.4a675061@.posting.google.c om...
> OK. For DDL, please refer to the classical Northwind ORDERS table,
> problem/challenge, find the longest duration (start_date and
> end_date), during which, no orders were placed.
> FYI, column names by the order of colid per syscolumns:
> OrderID
> CustomerID
> EmployeeID
> OrderDate
> RequiredDate
> ShippedDate
> ShipVia
> Freight
> ShipName
> ShipAddress
> ShipCity
> ShipRegion
> ShipPostalCode
> ShipCountry
> Any idea/approach? TIA.

No comments:

Post a Comment