开发者

MSAccess - Design query to group by anniversary date

开发者 https://www.devze.com 2022-12-19 05:50 出处:网络
Lets say I have a table with these fields LeaveDate LeaveType I want to write a querythat groups by an annivesary date.

Lets say I have a table with these fields

LeaveDate
LeaveType

I want to write a query that groups by an annivesary date.

For example say 8th Feb.

So for this year any dates after 8 Feb would be "2010" and any dates before 8 Feb would show开发者_JS百科 "2009".

I want this to occur for all years data.

Understand??

Malcolm


Here is how I did it

SELECT Year([tblFoo]![Leave_date])-IIf(DateDiff("d",[tblFoo]![Leave_date],DateSerial(Year([tblFoo]![Leave_date]),2,8))>0,1,0) AS Year_group, Count(tblFoo.ID) AS CountOfID

FROM tblFoo

GROUP BY Year([tblFoo]![Leave_date])-IIf(DateDiff("d",[tblFoo]![Leave_date],DateSerial(Year([tblFoo]![Leave_date]),2,8))>0,1,0);

This counts the number of records for each “Year”. We use something similar for working out birthday years which change from person to person. In that case use can just replace the fixed 2 and 8 with the month and day they were born


You could create a query with a calculated column for anniversary date, then group by that column.

0

精彩评论

暂无评论...
验证码 换一张
取 消