【select】
SELECT select_list
[INTO new_table]
FROM table_source
[WHERE search_condition]
[GROUP BY group_by_expression]
[HAVING search_condition]
[ORDER BY order_expression[ ASC | DESC ]]
- select demo
select * from persons where (firstname="" or firstname="") and lastname="";
select * from persons where lastname [not] between "" and "";
select distinct lastname from persons;
select lastname from persons order by lastname [ASC | DESC];
select company, sum(amount) from sales group by company;
select company, sum(amount) from sales group by company having sum(amount)>10000;
select count(column_name) from table_name;// sum, avg, max, min, abs, ceil, floor, cos, ...
- 关于join
select employees.name, orders.product from employees, orders where employees.id=orders.id;
select employees.name, orders.product from employees inner join orders on employees.id=orders.id;
- 取别名
select column as column_alias from table;
select column from table as table_alias;
【insert】
insert into table_name values (value1, value2, ...);
insert into table_name (column1, column2, ...) values (value1, value2, ...);
【update】
update person set firstname='', middlename='' where lastname='';
【delete】
delete from table_name where lastname='';
【create】
create table table_name (column1 data_type, column2 data_type);
【alter】
alter table table_name add columni datatype;
alter table table_name drop column column_name;
【drop】
drop table table_name;
【create db】
create database database_name;
【drop db】
drop database database_name;