7

2つの列の合計を取り、合計を除算する必要があります。両方の列は10進データ型です。これが私がこれまでに持っているもので、機能しません。

SELECT total_salary / DistEnroll
FROM   dbo.vw_Salary
WHERE  DistEnroll = (
           SELECT DISTINCT(distenroll)
           FROM   dbo.vw_Salary
           WHERE  YEAR = '2012'
                  AND dist_name = 'Sch Dist'
       )
       AND total_salary = (
               SELECT SUM(total_salary)
               FROM   [vw_salary]
               WHERE  YEAR = '2012'
                      AND dist_name = 'Sch Dist'
           )
4

1 に答える 1

8
select 
       ( select sum(total_salary) 
        from [vw_salary] 
        where year = '2012'
        and dist_name = 'Sch Dist') --totalsal
       /
       (select count(distinct distenroll) 
        from dbo.vw_Salary
        where year = '2012'
        and dist_name = 'Sch Dist') -- DistEnroll 

または、より良い:

        select sum(total_salary)  /  count(distinct distenroll) 
        from [vw_salary] 
        where year = '2012' and 
              dist_name = 'Sch Dist'  
于 2013-01-17T06:45:37.097 に答える