此代碼工作正常...
我與問題的工作,因爲早上,但我沒有得到什麼......所以,貼這個問題..但最後得到的答覆果然...
這裏是我的代碼
WITH mycte AS
(
SELECT Project_ID ,CONVERT(DATE, Start_Date,102) DateValue, Version_ID
from projects
UNION ALL
SELECT project_id, dateadd(mm, 1, DateValue), Version_ID
FROM mycte
WHERE year(DateValue) <= YEAR(GETDATE())
)
SELECT project_id, month(DateValue), year(datevalue), max(Version_ID) as version_id,
cast(cast(year(DateValue) as varchar(4)) +
RIGHT('0' + CAST(month(DateValue) AS VARCHAR(2)), 2) +
RIGHT('0' + CAST('01' AS VARCHAR(2)), 2) as date) as start_date
FROM mycte
--where project_id = 111
group by project_id, month(DateValue), year(datevalue)
having max(year(datevalue)) <= year(getdate())
OPTION (MAXRECURSION 0)
首先,你爲什麼要標記的MySQL?其次,先寫一些代碼,我們不是爲你擔心的。 – DavidG
我已經寫了一個代碼,這是隻適用於當前年份或特定年份的CTE –
的幫助共享此代碼 – cha