根据 group by 查找最大创建日期小于某时间的:
select company_id from market_prices group by company_id having max(created_at) < '2020-02-02 23:59:59'
根据 group by 查找最大创建日期小于某时间的且符合一定条件的公司数量:
select count(*) from (select distinct company_id from market_prices group by company_id having max(created_at) < '2020-02-02 23:59:59') temp inner join companies on companies.id = temp.company_id where companies.is_hidden = false
网友评论