(相關(guān)資料圖)
GROUP BY子句
GROUP BY子句用于對檢索結(jié)果進行分組。其基本語法如下:
SELECT column1, column2, ... FROM table_name GROUP BY column_name;
其中,column_name是要分組的列名。例如,從students表中按性別分組,并統(tǒng)計每個分組的平均成績:
SELECT gender, AVG(score) FROM students GROUP BY gender;
HAVING子句
HAVING子句用于篩選分組后的數(shù)據(jù)。其基本語法如下:
SELECT column1, column2, ... FROM table_name GROUP BY column_name HAVING condition;
其中,condition是篩選條件。例如,從students表中按性別分組,并篩選平均成績大于80的分組:
SELECT gender, AVG(score) FROM students GROUP BY gender HAVING AVG(score) > 80;
UPDATE語句
UPDATE語句用于更新表中的數(shù)據(jù)。其基本語法如下:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
其中,column1, column2, ...是要更新的列名和數(shù)據(jù)值,condition是篩選條件。例如,將students表中年齡小于18歲的學生的成績?nèi)吭O(shè)為60分:
UPDATE students SET score = 60 WHERE age < 18;
DELETE語句
DELETE語句用于刪除表中的數(shù)據(jù)。其基本語法如下:
DELETE FROM table_name WHERE condition;
其中,condition是篩選條件。例如,刪除students表中成績小于60分的學生的記錄:
DELETE FROM students WHERE score < 60;
關(guān)鍵詞: