我正在尝试使用以下查询计算两列:
select distinct [District],
count (Distinct [Student Identifier Statewide California])
as '11-12 Enrollment',
(select count (Distinct IncdtKey)
From [dbo].[DisciplineStudentFile1112]
where GrdLvLKey in ('15', '01', '02', '03', '04',
'05', '06', '07', '08', '09',
'10', '11', '12', '18', '19')) as Total_Incidents
From
dbo.SSID1112StudentEnrollmentRecords with (nolock)
inner join
[dbo].[SchoolDetail] on CDSCode = dbo.SSID1112StudentEnrollmentRecords.CDSOrig
where
[EnrollStatCodeOrig] like '10'
and
[Grade Level Code] in ('PS', 'KN', '01', '02', '03',
'04', '05', '06', '07', '08',
'09', '10', '11', '12', 'UE', 'US')
group by [District]
order by [District]
我的结果是:
District 11-12 Enrollment Total_Incidents
AB Unified 20662 896371
CE Unified 5387 896371
DR Unified 526 896371
FJ Unified 1506 896371
KT Unified 8415 896371
我不知道如何获得Total_Incidents
列中的单个计数而不是总计数 896371?