SQL查询按名称平均

时间:2018-07-10 09:02:28

标签: mysql sql-server

我有以下数据:

    criteria    rating

    Criteria1   3
    Criteria2   3
    Criteria3   3
    Criteria5   3
    Criteria1   5
    Criteria2   5
    Criteria3   5
    Criteria5   1

我想按标准名称(例如:

)对每个等级进行平均

预期输出:

    criteria    rating

    Criteria1   4
    Criteria2   4
    Criteria3   4
    Criteria5   2

有人可以帮助我实现这一目标吗?

3 个答案:

答案 0 :(得分:1)

Select criteria, avg(rating) as rating from tbl group by criteria

答案 1 :(得分:0)

这应该可以完成工作:

SELECT criteria, AVG(rating) FROM <table_name>
GROUP BY criteria;

答案 2 :(得分:0)

SELECT Criteria, 
        AVG(rating) 
             From YourTable 
             GROUP BY Criteria 
             ORDER BY Criteria