gpt4 book ai didi

sql - 两列之和之间的除法

转载 作者:行者123 更新时间:2023-12-04 14:47:14 25 4
gpt4 key购买 nike

我需要取两列的总和并除以总数。两列都是十进制数据类型。这是我到目前为止不起作用的内容。

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'
)

最佳答案

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'

关于sql - 两列之和之间的除法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14373466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com