문제

I have the following query in which I am trying to create a field that counts the number of days for a year. The issue is that when I get to 2014, it keeps counting and I need it to start back at 1.

SELECT
    IJDATE,
    ROW_NUMBER() OVER( ORDER BY IJDATE ) AS 'InvoiceDay'
FROM
    S2K_IJ
WHERE
    IJTYPE = '1'
AND
    YEAR(IJDATE) > 2012
GROUP BY
    IJDATE
ORDER BY
    IJDATE
GO
도움이 되었습니까?

해결책

SELECT
    IJDATE,
    ROW_NUMBER() OVER( partition by year(IJDATE) ORDER BY IJDATE ) AS 'InvoiceDay'
FROM
    S2K_IJ
WHERE
    IJTYPE = '1'
AND
    YEAR(IJDATE) > 2012
GROUP BY
    IJDATE
ORDER BY
    IJDATE
GO

You need to partition by the year so that it starts the count from 1.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top