DECLARE @workflowTable AS TABLE (company varchar(50), wor...


Please login or register to vote for this query.

(click on this box to dismiss)

Ask Ubuntu Meta

Q&A about the site for Ubuntu users and developers

DECLARE @workflowTable AS TABLE (company varchar(50), workflow varchar(50), [date] datetime)
('CompanyA',      'Workflow27',     'June 5 2011')
,('CompanyA',      'Workflow27',     'June 8 2011')
,('CompanyA',      'Workflow27',     'June 8 2011')
,('CompanyA',      'Workflow27',     'June 12 2011')
,('CompanyB',      'Workflow13',     'Apr 4 2011')
,('CompanyB',      'Workflow13',     'Apr 9 2011')
,('CompanyB',      'Workflow20',     'Dec 11 2011')
,('CompanyB',      'Workflow20',     'Dec 17 2011')

;WITH partitioned AS (
        SELECT company
            -- ,other_columns
            ,ROW_NUMBER() OVER(PARTITION BY company, workflow
                                ORDER BY date) AS seq
        FROM @workflowTable
    SELECT a.workflow,, b.counted
    FROM partitioned a 
    join (select workflow, date, count(*) as counted from partitioned group by workflow, date) b
    on b.workflow = a.workflow
    and = 
    where seq = 2

    group by a.workflow,, b.counted

Enter Parameters

Switch to main site
loading Hold tight while we fetch your results