我正在try 使用SQL中的COUNT函数将一些数据分三部分提取到我的ASP.NET项目中:
第一部分将使用第一个SQL查询,如下所示:
select distict, shop_number, count(Emp_id)
from Shops_and_Employee_Table
group by distict, shop_number
第二部分将使用第二个SQL查询:
select distict, shop_number, count(Emp_id)
from Shops_and_Employee_Table
where score >= 80
group by distict, shop_number
在我的项目中,我在2个不同的GridView中显示了上述结果.
现在我需要显示一个新的GridView,以获得第二个查询与第一个查询的平均值,我使用了以下命令,但没有获得正确的结果:
select
a.distict, a.shop_number, b.number / a.number
from
(select distict, shop_number, count(Emp_id) as number
from Shops_and_Employee_Table
group by distict, shop_number) a
join
(select distict, shop_number, count(Emp_id) as number
from Shops_and_Employee_Table
where score >= 80
group by distict, shop_number) b on a.shop_number = b.shop_number
谁能告诉我,我在我的平均查询中写了什么?或者建议我自己对C#代码中的数字求平均,但解释一下,因为我不知道如何应用它.
等待您的大力帮助.
我试着用SQL本身做,但我弄错了数字,有人告诉我用后面的C#代码做得更好,但我做不到,请帮帮我.