如何将Query2中的Query2与第二个参数以及带有条件的现有Select count(*)语句组合在一起。
-------------------查询1 - 主要查询以退出来源&表计数--------
select Count(distinct(SUBSTRING(pathSuffix,
CHARINDEX('-', pathSuffix)+1,
LEN(pathSuffix)- (CHARINDEX('-',REVERSE(pathSuffix)) + CHARINDEX('-', pathSuffix)))))
from Sources s with(nolock)
where parent like '/prod/snapshot_rpx/archive%' and type='FILE' and level=2
---------- Query2 - 获取Snapshot_rpx文件的计数为495 ----------------
<system.web>
<compilation debug="false" targetFramework="4.0"/>
</system.web>
答案 0 :(得分:0)
您可以使用子查询:
select Count(distinct(SUBSTRING(pathSuffix, CHARINDEX('-', pathSuffix)+1, LEN(pathSuffix)- (CHARINDEX('-',REVERSE(pathSuffix)) + CHARINDEX('-', pathSuffix))))), (Select count(*) from Sources with(nolock) where level = 2 and ( (parent like '%raw%' and type= 'DIRECTORY' AND parent like '/prod/' + s.pathSuffix + '/raw') or (parent like '%archive%' and type='DIRECTORY' and parent like '/prod/' + s.pathSuffix + '/archive') )) as filecount, modificationTime, owner, type
from Sources s with(nolock) where level = 0 order by pathSuffix) from Sources s with(nolock) where parent like '/prod/snapshot_rpx/archive%' and type='FILE' and level=2