简体   繁体   English

MS Access选择不同的记录

[英]MS Access Selecting Distinct Records

I am using MS Access 2010: 我正在使用MS Access 2010:

I am working on a calendar and would like to show the unique events types each day.. Can someone help me out wit this.. 我正在制作日历,并希望每天显示独特的事件类型。.有人可以帮我这个忙..

This is what the table looks like 这是桌子的样子

Events 活动

 - Event_ID (PK)
 - Event_type_id (FK)
 - Event_name
 - Event_Date

This is my data: 这是我的数据:

1, 1, Test Event 0, 06/06/2014    
2, 1, Test Event 1, 06/06/2014   
3, 1, Test Event 2, 06/07/2014    
4, 2, Test Event 3, 06/07/2014    
5, 3, Test Event 4, 06/09/2014

I need the query to only return 1 event of each type each for each date.. 我需要查询仅在每个日期返回每种每种类型的1个事件。

You can do this with a clever where clause: 您可以使用聪明的where子句来做到这一点:

select e.*
from Events as e
where not exists (select 1
                  from Events as e2
                  where e2.event_date = e.event_date and e2.event_type_id = e.event_type_id and
                        e2.event_id > e.event_id
                 );

This will return the rows with the largest event id on each date for each type. 这将返回每种类型在每个日期具有最大事件ID的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM