首页 > 代码库 > sql 语句

sql 语句

INSERT

基本语法:INSERT INTO table_name VALUES(value1,value2,value3,...); 

指定列:INSERT INTO table_name(column1, column2, column3,…) VALUES(value1,value2,value3,...);

UPDATE

UPDATE table_name set column1=‘new_value‘,column2=‘new_value‘,...;

DELETE

DELETE from table_name;

SELECT

SELECT column1,column2,column3,... from table_name; or

SELECT *  from table_name;

WHERE condition GROUP BY column1,column2,...HAVING condition

分组有据(select columns 有该字段),先有结果集(可以是where帅选过的),再依据唯一性分组,然后统计,最后过滤结果集。

a sample Employees table

技术分享

求各个部门的总工资:

SELECT DEPARTMENT_ID,SUM(SALARY) as Total_Salary FROM EmployeesGROUP BY DEPARTMENT_ID;

group by DEPARTMENT_ID后具有相同DEPARTMENT_ID的数据项聚集在一起,然后以函数的形式合并成一条记录,DEPARTMENT_ID具备了唯一性(group by后的字段组合具有唯一性)。

技术分享

 

sql 语句