我已经为 oracle 编写了一个 SQL 查询,我想选择我正在查询的另一个值的每组中具有最低值的记录。我所写的似乎有效,但我不确定它是否真的正确。
select cam.visible_id campaign_id,
ps.visible_id plate_set_id,
ps.alias plate_set_name,
ps.date_created date_created,
count(distinct(iw.isolate_id)) number_of_clones
from plate_set ps
join campaign cam on cam.id = ps.campaign_id
join plate_plate_set pps on pps.plate_set_id = ps.id
join plate p on p.id = pps.plate_id
join plate_type pt on pt.id = p.plate_type_id
join isolate_well iw on iw.plate_id = p.id
where pt.label='Master Plate'
and ps.date_created = (select min(ps2.date_created) from plate_set ps2 where ps2.campaign_id = cam.id)
group by cam.visible_id, ps.alias, ps.visible_id, ps.date_created
order by cam.visible_id
;
我不明白我的查询是如何在 where 子句中工作的:
and ps.date_created = (select min(ps2.date_created)
from plate_set ps2
where ps2.campaign_id = cam.id)
在我看来,ps.date_created 应该是一个连接,其中 ps.date_created = 在每个广告系列中创建的第一个板组
就像是
join (
select min(plate_set.date_created) as created_date
from plate_set
join campaign on plate_set.campaign_id
group by campaign.id
) helperTable on helperTable.NotSureHowToJoinLikeThis on ps.date_created
我实际上是正确的,sql查询活动ID然后过滤创建日期最低的行,或者有人可以帮助我加入我应该做的更好写吗?