4
サブクエリに相当する内部結合を作成しました。誰かが私にそれが正しいやり方であり、より効率的な方法であるかどうかを知らせてもらえますか? ONキーワードが内側句内部結合とサブクエリの照合が必要
サブクエリ
select
companyId,
fiscalYear,
fiscalQuarter,
periodenddate
into #PeriodTbl
from(
select
fp.companyId,
fp.fiscalYear,
fp.fiscalQuarter,
fi.periodenddate,
ROW_NUMBER() OVER (PARTITION BY fp.companyId, fp.fiscalYear, fp.fiscalQuarter ORDER BY fi.periodEndDate DESC) rowno
from ciqfinperiod fp
join ciqfininstance fi on fi.financialperiodid = fp.financialperiodid
where fp.periodtypeid = 4
and fi.periodenddate > @date
and fi.latestforfinancialperiodflag = 1
and latestfilingforinstanceflag = 1
and fp.companyId in (select id from #companyId)
) a
where a.rowno = 1
は、一般に
select
companyId,
fiscalYear,
fiscalQuarter,
periodenddate
into #PeriodTbl
from(
select
fp.companyId,
fp.fiscalYear,
fp.fiscalQuarter,
fi.periodenddate,
ROW_NUMBER() OVER (PARTITION BY fp.companyId, fp.fiscalYear, fp.fiscalQuarter ORDER BY fi.periodEndDate DESC) rowno
from ciqfinperiod fp inner join #companyId ci on fp.companyId = ci.id
join ciqfininstance fi on fi.financialperiodid = fp.financialperiodid
where fp.periodtypeid = 4
and fi.periodenddate > @date
and fi.latestforfinancialperiodflag = 1
and latestfilingforinstanceflag = 1
--and fp.companyId in (select id from #companyId)
) a
where a.rowno = 1