Numbering a group

  • Hi, I have the following sample data, I would like the following result

    data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAY8AAAFeCAYAAAB9+JNtAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACFPSURBVHhe7d39ixzJecDxR/kL7DvwW3bBkiWB5RtzEHzcjkAELyYn3Q9jgpkYK8GbEGsPDL6BSdhgTveDdRgrzoY5g+FWDkEhlnEGY3sJ1jmYDeZAs+aM4fDIMki6lc1u8MXgy/0Fdqqqq2e6Z/utemZ6Xur7gUY7O+rdeWp7+umq6qnnxB8UATAX9vf3ZW1tzT4C5tcf2X8BACiM5AEAcEbyAAA4I3kAAJyRPAAAzkgeAABnJA8AgDOSBwDAGckDAOCM5AEAcEbyAAA4I3kAAJyRPAAAzkgeAABnJA8AgDOSBwDAGckDAOCM5AEAcEbyAAA4I3kAAJyRPAAAzkgeAABnJA8AgLMTf1Ds1wBmbH9/334FzDeSBwDAGcNWAABnJA8AgDOSBwDAGckDAOCM5AEAcEbyAAA4I3kAAJyRPAAAzkgeAABnsU+Y//znP5d3vetd9pF/3nnnHeInfvvIP8T/jnz0ox+1j/zj+veP9Tx+//vf26/8RPzE7zPi9zt+15WqSB4RxE/8PiN+4ndB8oggfuL3GfH7Hb9rzyM25/H666/L+973PvuoSr+Rb996UV75nfry8T+Xf798UVaDJyr11ltvzSD+N+QrX/u6/NA+Cj3z7DfkHz5kH1RkNvGHjrfD2bUvyY2Pvd8+mr7q448c9zGr8txfviiffsw+rAjH/1vy1FNP2Uf++e1vfyvvec977KN889HzePsN+e/wDfS7n8qdt+3XFZunK48f/uBL8u2K22F2f/9X5UrCCaRq8/P3P5RXvvk5ufLT39jH1fD9ynt28ffk+ic+IZ+IbM/9x6F9rjoLOedx+OZP5b7695mzT+tH8t9vVvumCc32zfO0fPkL35Aff+Hz8ox5fCi/+j/zRWVmE7+68vzmd83f3/Q6TRsE7fBx83x1Zvf31z2NMO4vyXO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wAAM5IHgAAZyQPAIAzkgcAwBnJAwDgjOQBAHBG8gAAOCN5AACckTwAAM5IHgAAZyQPAIAzkgcAwBnJAwDgjOQBAHBG8gAAOCN5AACcnfjlL39pignq7d69e/LhD3/YPgUAQDLK0EZQhpT4iZ/4feUaP8NWAABnJA8AgDOSBwDAGckDAOCM5AEAcEbyAAA4I3kAAJyRPAAAzkgeAABnJA8AgDOSBwDAGckDAOCM5AEAcEbyAAA4I3kAAJyRPAAAzkgeAABnJA8AgDNqmAMAnFHDPIIaxsRP/MTvK9f4GbYCADgjeQAAnJE8AADOSB4AAGckDwCAM5IHAMAZyQMA4IzkAQBwRvIAADgjeQAAnJE8AADOSB4AAGckDwCAM5IHAMAZyQMA4IzkAQBwRvIAADgjeQAAnFHDHADgjBrmEdQwJn7iJ35fucbPsBUAwBnJAwDgjOQBAHBG8gAAOCN5AACckTwAAM5IHgAAZyQPAIAzkgcAwBnJAwDgjOQBAHBG8gAAOCN5AACckTwAAM5IHgAAZyQPAIAzkgcAwBnJAwDgjBrmAABn1DCPoIYx8RM/8fvKNX6GrQAAzkgeAABnJA8AgDOSBwDAGckDAOCM5AEAcEbyAAA4I3kAAJyRPAAAzkgeAABnJA8AgDOSBwDAGckDAOCM5AEAcCTy/43FcwUYYn98AAAAAElFTkSuQmCC

    create table dta

    (

    LongRunN2 int null

    ,Site Varchar(1)

    ,SubSite Varchar(20)

    ,MonthStart Varchar(10)

    )

    insert into dta

    values ('1', 'A','AA','01-01-2017'),

    ('1', 'B','BB','01-02-2017'),

    ('1', 'C','CC','01-03-2017'),

    (NULL, 'D','DD','01-04-2017'),

    ('1', 'E','EE','01-05-2017'),

    ('1', 'F','FF','01-06-2017'),

    ('1', 'G','GG','01-07-2017'),

    (NULL, 'H','HH','01-08-2017'),

    (NULL, 'I','II','01-09-2017'),

    (NULL, 'J','JJ','01-10-2017')

    Select * from dta

  • Not much to go on, but perhaps:
    SELECT *,
          CASE WHEN LongRunN2 IS NULL THEN NULL
                ELSE (SELECT COUNT(*)
                      FROM dta sq
                      WHERE sq.MonthStart <= dta.MonthStart
                        AND sq.LongRunN2 IS NULL) + 1 END AS LongRun
    FROM dta;

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • This option might help avoid a triangular join.

    WITH CTE AS(
      Select *,
       ROW_NUMBER() OVER( ORDER BY MonthStart) -
       ROW_NUMBER() OVER( PARTITION BY LongRunN2 ORDER BY MonthStart) grouper
      from dta
    )
    SELECT *,
       CASE WHEN LongRunN2 IS NOT NULL
          THEN DENSE_RANK() OVER(PARTITION BY LongRunN2 ORDER BY grouper)
          END
    FROM CTE
    ORDER BY MonthStart;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares - Monday, July 31, 2017 8:48 AM

    This option might help avoid a triangular join.

    WITH CTE AS(
      Select *,
       ROW_NUMBER() OVER( ORDER BY MonthStart) -
       ROW_NUMBER() OVER( PARTITION BY LongRunN2 ORDER BY MonthStart) grouper
      from dta
    )
    SELECT *,
       CASE WHEN LongRunN2 IS NOT NULL
          THEN DENSE_RANK() OVER(PARTITION BY LongRunN2 ORDER BY grouper)
          END
    FROM CTE
    ORDER BY MonthStart;

    hi thank you I made a bit of a mistake the groups of 1s all belong to the same site and sub site for instance the first set of 1s (LongRunN2) is A, AA and the seconds set is E,EE\

    how can I ensure that this is included in the calculation thanks again ,

  • Thank you Ive just added them into the partition thank you again

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply