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