在 SQL 中增长 HAVING 子句缘由是,WHERE 关键字没法与聚合函数一块儿使用。html
HAVING 子句可让咱们筛选分组后的各组数据。sql
SELECT Websites.name, Websites.url, SUM(access_log.count) AS nums FROM (access_log INNER JOIN Websites ON access_log.site_id=Websites.id) GROUP BY Websites.name HAVING SUM(access_log.count) > 200;
name like '张%'
having avg(score)>75
select * from student where name in (select name from student where name like '张%' group by name having avg(score) > 75)
SELECT S.name FROM Student S GROUP BY S.name Having MIN(S.score)>=80
SELECT * FROM TableX WHERE Name LIKE '张%' ORDER BY Age;
SELECT * FROM TableX x, TableY y WHERE x.Code = y.Code AND Class = '计算机' AND Score < 60;
SELECT x.Name, y.Class, y.Score FROM TableX x, TableY y WHERE x.Code = y.Code
Left Out:SELECT x.Name, y.Class, y.Score FROM TableX x, TableY y WHERE x.Code = y.Code(+) Right Out: SELECT x.Name, y.Class, y.Score FROM TableX x, TableY y WHERE x.Code(+) = y.Code Full Out:Left join union all right join
INSERT INTO TableX(Code, Name, Age) VALUES('97005','赵六',20);
COMMIT;
UPDATE TableX SET Age = 21 WHERE Code in (SELECT Code FROM TableX WHERE Name = '李五')
DELETE FROM TableX WHERE Code Not in (SELECT Code FROM TableY WHERE NVL(Score,0) = 0)