AVG()

Функція розрахунку середнього значення

SELECT AVG(Price)

FROM Products;

[ Перевір себе тут ]

C#

string sSQL = "SELECT AVG(Salary) FROM [dbo].[Table]";

string cn_txt = Properties.Settings.Default.cn;

SqlConnection cn_connection = new SqlConnection(cn_txt);

if (cn_connection.State != ConnectionState.Open)

{

     cn_connection.Open();

}

using (SqlCommand cmd = new SqlCommand(sSQL, cn_connection))

{

     var result = cmd.ExecuteScalar(); 

     if (result == null)

     {

          MessageBox.Show("Nothing");

     }

     else

     {

          MessageBox.Show(result.ToString());

     }

}