Ms access Acces:选择每个产品的最新日期行
我将此表命名为Transaction: 我正在尝试对Access进行SQL查询,以查找每个产品的最新关联日期。结果应该是这样的:(我想查看数量以及日期和产品名称)Ms access Acces:选择每个产品的最新日期行,ms-access,greatest-n-per-group,Ms Access,Greatest N Per Group,我将此表命名为Transaction: 我正在尝试对Access进行SQL查询,以查找每个产品的最新关联日期。结果应该是这样的:(我想查看数量以及日期和产品名称) 谢谢考虑使用子查询进行筛选: select t.* from transactions t where t.date = ( select max(t1.date) from transactions t1 where t1.product = t.product ) 如果您使用的是MySQL 8.0,请
谢谢考虑使用子查询进行筛选:
select t.*
from transactions t
where t.date = (
select max(t1.date)
from transactions t1
where t1.product = t.product
)
如果您使用的是MySQL 8.0,请尝试使用
row\u number
select
id,
quantity,
date
from
(
select
id,
quantity,
date,
row_number() over (partition by product order by date desc) as rn
from transaction
) subq
where rn = 1
在选择最新(
max
)日期时,必须按产品对行进行分组:
嗨,做完这件事后,我得到了一些相同产品的记录。我希望每个产品都有一次约会。(最近的日期)您使用的是哪个版本的MySQL?我使用的是access 2007-2016,我不确定在哪里可以查看我的MySQL版本。对不起,我没听清楚。您使用的是MS Access还是MySql?
select t.product, t.quantity, t.date
from transaction t
inner join (
select product, max(date) as MaxDate
from transaction
group by product
) tm on t.product = tm.product and t.date = tm.MaxDate