December 6, 2013 at 6:45 am
December 6, 2013 at 6:46 am
December 6, 2013 at 8:17 am
;WITH cte (FromID,ToID,SalesIndicator,GroupNO) AS (
SELECT t1.ID,t2.ID,CASE WHEN t1.Sales < t2.Sales THEN 'UP' ELSE 'Down' END
,t1.ID-ROW_NUMBER() OVER (PARTITION BY CASE WHEN t1.Sales < t2.Sales THEN 'UP' ELSE 'Down' END ORDER BY t1.ID)
FROM sales t1
JOIN sales t2 ON t2.ID = t1.ID+1)
SELECT MIN(FromID) AS [FromID],MAX(ToID) AS [ToID],SalesIndicator
FROM cte
GROUP BY GroupNo,SalesIndicator
ORDER BY FromID ASC
Far away is close at hand in the images of elsewhere.
Anon.
December 9, 2013 at 12:25 am
Thank You...It worked!!!:-):-):-)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply