在 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)