Reputation: 667
I have a Table having 2 Columns i.e FarmerName,PesticideUsed and Town.
There are 29 unique Pesticides And 8 Unique Towns.
I tried to write the first one i.e
adapter.SelectCommand = new SqlCommand(
"select count(FarmerName)/29 as average_count from try", con);
I dont think it is right.
How i am i going to do that....
Upvotes: 0
Views: 136
Reputation: 21657
Average number of farmers using a pesticide:
SELECT PesticideUsed ,AVG(num)
FROM (
SElECT PesticideUsed ,COUNT(*) as num
FROM yourTable
GROUP BY PesticideUsed) a
GROUP BY PesticideUsed
Average number of farmers per town:
SELECT town ,AVG(num)
FROM (
SElECT town ,COUNT(*) as num
FROM yourTable
GROUP BY town) a
GROUP BY town
Upvotes: 9
Reputation: 1
try this instead.
adapter.SelectCommand = new SqlCommand( "select AVG(FarmerName) as average_count from try", con);
Upvotes: -2