我有以下查询,其中我正在尝试创建一个计算一年天数的字段。问题是,当我到2014年时,它一直在计算,我需要它从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
答案 0 :(得分:1)
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
您需要按年份进行分区,以便从1开始计数。