简体   繁体   English

SQL到MS Access SQL查询

[英]SQL To MS Access SQL Query

Hello SQL/MS Access community! 您好SQL / MS Access社区! I have a problem! 我有个问题! I have a query in SQL that gets the top record for each group and it works great! 我在SQL中有一个查询,可以查询每个组的最高记录,而且效果很好! However, I need this to be a query in Microsoft Access. 但是,我需要将其作为Microsoft Access中的查询。 Is there anyone out there that can help me with translating it? 有没有人可以帮助我进行翻译? I do not know coding at all (I can pick it apart to understand it, but I can't write it unfortunately). 我一点都不了解编码(我可以将其分开理解,但不幸的是我不能编写它)。 Any help is much appreciated! 任何帮助深表感谢!

SELECT * FROM Table1; WITH summary AS ( SELECT p.PK_ID, p.Field1, p.Field2, ROW_NUMBER() OVER (PARTITION BY p.PK_ID ORDER BY p.Field1 DESC) AS rk FROM Table1 p) SELECT s.* FROM summary s WHERE s.rk=1

You are trying to get the first record (based on Field1 ) for each pk_id . 您正在尝试获取每个pk_id的第一条记录(基于Field1 )。 Something like this may work for you: 这样的事情可能适合您:

select p.*
from table1 as p
where p.field1 = (select max(p2.field1)
                  from table1 as p2
                  where p2.pk_id = p.pk_id
                 );

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

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