SQLite Having语句

SQLite HAVING 子句用于指定筛选最终结果中显示的组结果的条件。WHERE 子句对所选列放置条件,而 HAVING 子句对由 GROUP BY 子句创建的组放置条件。

HAVING 子句在 SELECT 查询中的位置:

SELECT  
FROM  
WHERE  
GROUP BY  
HAVING  
ORDER BY  

语法:

SELECT  
FROM  
WHERE  
GROUP BY  
HAVING  
ORDER BY  

示例:

让我们举一个例子来演示 HAVING 子句。我们有一个名为“STUDENT”的表,其中包含以下数据:

示例 1:

显示名称计数小于 2 的所有记录:

SELECT * FROM STUDENT GROUP BY NAME HAVING COUNT(NAME) < 2;   

输出结果:

示例 2:

显示名称计数大于 2 的所有记录:

SELECT * FROM STUDENT GROUP BY NAME HAVING COUNT(NAME) > 2;  

输出结果:

热门文章

优秀文章