我有一个包含2个列的表,即FarmerName,PesticideUsed和Town。
有29种独特的农药和8个独特的城镇。
我试着写第一个,即
adapter.SelectCommand = new SqlCommand(
"select count(FarmerName)/29 as average_count from try", con);
我不认为这是对的。
我将如何做到这一点......
答案 0 :(得分:9)
使用农药的农民平均数量:
SELECT PesticideUsed ,AVG(num)
FROM (
SElECT PesticideUsed ,COUNT(*) as num
FROM yourTable
GROUP BY PesticideUsed) a
GROUP BY PesticideUsed
每个城镇的平均农民数量:
SELECT town ,AVG(num)
FROM (
SElECT town ,COUNT(*) as num
FROM yourTable
GROUP BY town) a
GROUP BY town
答案 1 :(得分:-2)
试试这个。
adapter.SelectCommand = new SqlCommand( “选择AVG(FarmerName)作为average_count从try”,con);