4
我寫了一個子查詢的內部連接等效項。有人能讓我知道這是否是正確的做事方式,如果是更有效的方式。是否開啓關鍵字過濾方式where子句需要驗證內部連接和子查詢
子查詢
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