如何在sql中的每个百分位内获得列x的中位数?

问题描述

sql 中是否有代码可以让我在我在一个 select 语句中提取的每个百分位数内获得列 x 的中位数?这是我拉的百分位数。我试图避免单独编码中位数并将它们合并在一起。谢谢!

private string CheckData(string firstValue,string SecondValue,int Active)
{
    string Data = "";

    StringBuilder sb = new StringBuilder();
    string query = @"select M.ident Mi,mmp.active Active 
                     from Iden.Iden M
                     inner join PtM.MPt MMP on MMP.mPat = M.id
                     where M.ident = 'firstValue' 
                       and Mi.ident = 'SecondValue'";
    sb.Append(query);

    sb.Replace("firstValue",firstValue);
    sb.Replace("SecondValue",SecondValue);
            
    sqlConnection connection = new sqlConnection(connString);

    sqlCommand cmd = new sqlCommand(sb.ToString());
    cmd.CommandTimeout = 0;
    cmd.CommandType = CommandType.Text;
    cmd.Connection = connection;

    try
    {
        connection.open();

        sqlDataReader reader = cmd.ExecuteReader();

        if (reader.HasRows)
        {
            while (reader.Read())
            {
                Data = reader.GetString(reader.Getordinal("Mi"));
                Active = reader.GetInt32(reader.Getordinal("Active"));
            }
        }
    }
    catch (Exception ex)
    {
        _log.Error($"Exception:{ex.Message}");
    }
    finally
    {
        connection.Close();
        connection.dispose();
    }

    return Data;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)