SQL-查找介于0和平均人口之间的百分比人口

时间:2019-04-20 14:16:53

标签: mysql sql group-by aggregate-functions

我正在尝试查找介于0和该组平均值之间的每个分组行的人口百分比。例如,在下面的查询中,说我有一个行,其中num_problems为100,平均值为70。总体(该行)中有58个值,其值小于70。我想将值(58)提取为结果图钉的一部分。

select
    tm.subject_name,
    tm.topic_name,
    pm.problem_type,
    count( pa.id ) as num_problems,
    avg( pa.duration ) as average ,
    stddev( pa.duration )
from
    problem_attempt pa,
    problem_master pm,
    topic_master tm
where
    pa.problem_id = pm.id and
    pm.topic_id = tm.id and
    pa.outcome = 'Solved' and
    pa.duration > 10 and 
    pa.duration < 1000 and
    pm.problem_type = 'SCA'
group by
    tm.subject_name,
    tm.topic_name,
    pm.problem_type ;

1 个答案:

答案 0 :(得分:0)

从不@section Scripts { @Scripts.Render("~/bundles/jqueryval") <script> function prideti(sk) { var tmp_row = `<tr> <td> @Html.EditorFor(model => model.dalyviai[0].vardas, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.dalyviai[0].vardas, "", new { @class = "text-danger" }) </td> <td> @Html.EditorFor(model => model.dalyviai[0].pavarde, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.dalyviai[0].pavarde, "", new { @class = "text-danger" }) </td> <td> @Html.EditorFor(model => model.dalyviai[0].telefonas, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.dalyviai[0].telefonas, "", new { @class = "text-danger" }) </td> <td> @Html.EditorFor(model => model.dalyviai[0].el_pastas, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.dalyviai[0].el_pastas, "", new { @class = "text-danger" }) </td> <td> @Html.DropDownListFor(model => model.dalyviai[0].fk_projektas, Model.projektaiList, "--------------", new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.dalyviai[0].fk_projektas, "", new { @class = "text-danger" }) </td> </tr>`; $("#kainos_tbl tr:last").after(tmp_row); $('#hCount').val(Number($('#hCount').val()) + 1); $(".date-picker").datepicker({ dateFormat: 'yy-mm-dd' }); }; `` 子句中使用逗号。 始终使用正确的,明确的,标准 FROM语法。

您需要聚合两次或使用窗口函数。

我建议:

JOIN