按声明命令后的声明

时间:2017-05-03 15:54:51

标签: sql

我想在AVG摸索后询问值>在8,像这样的东西

SELECT avg(students_subject.nota) as avg, students.name
FROM students_subject
left JOIN studentsON students.id=students_subject.id_alumno
GROUP BY students_subject.id_student 
where avg > 8;

3 个答案:

答案 0 :(得分:2)

对引用聚合函数的条件使用having子句:

SELECT avg(students_subject.nota) as avg, students.name
FROM students_subject
left JOIN students ON students.id=students_subject.id_alumno
GROUP BY students_subject.id_student 
having avg(students_subject.nota)> 8;

答案 1 :(得分:2)

与GROUP BY比较时使用 HAVING WHERE 无法与聚合函数一起使用。您的查询将如下所示:

var openCloseGallery = function () {
    function openCloseAnimation(action) {
        if (action) {               // 1 -> OPEN
            $(galleryDiv).parent().addClass('animate-open-gallery');
            $(superWrapperDiv).addClass('animate-close-superwrapper');
            $('body').css('overflow', 'hidden');
        } else {                    // 0 -> CLOSE
            $(galleryDiv).parent().removeClass('animate-open-gallery').addClass('animate-close-gallery');
            $(superWrapperDiv).removeClass('animate-close-superwrapper').addClass('animate-open-superwrapper');
            $('body').css('overflow', 'auto');
        }
    }

    var desktopEvents = function () {
        $(openGalleryDiv).click(openCloseAnimation(true));
        $(closeGalleryDiv).click(openCloseAnimation(false));
    });
});

答案 2 :(得分:1)

参考网站w3schools

语法

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);

实施例

SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;