Get all StudentIds for each consecutive date

  • SELECT          StudentId
    FROM @student
    GROUP BY StudentId
    HAVING COUNT(DISTINCT SubmissionDate) > GREATEST(2, DATEDIFF(DAY, MIN(SubmissionDate), MAX(SubmissionDate)));

    N 56°04'39.16"
    E 12°55'05.25"

  • SwePeso wrote:

    SELECT          StudentId
    FROM @student
    GROUP BY StudentId
    HAVING COUNT(DISTINCT SubmissionDate) > GREATEST(2, DATEDIFF(DAY, MIN(SubmissionDate), MAX(SubmissionDate)));

    Unfortunately, GREATEST isn't available in 2019, which is what this forum is.

    That is a pretty cool usage of greatest though.

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • You can substitute this simple GREATEST with a CASE WHEN THEN END statement.


    N 56°04'39.16"
    E 12°55'05.25"

  • SwePeso wrote:

    You can substitute this simple GREATEST with a CASE WHEN THEN END statement.

    Since GREATEST isn't available in 2019, you should post that change to the code for the OP. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 16 through 18 (of 18 total)

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