创建表
create table user_b(
id int not null primary key ,
name char ( 20 ) not null
) ;
删除表
drop table xxx;
eg:drop table user_b;
添加字段
alter table user_b add ( count int not null ) ;
alter table user_b add ( title varchar ( 100 ) ) ;
移除字段
alter table user_b drop column count;
变更字段
alter table user_b modify column title varchar ( 255 ) ;
插入数据
插入一条完整数据
insert into user_b values ( 1 , '房价啥时候降下来' , 10 ) ;
单表查询
select * from user_b;
select title from user_b;
select title from user_b where count> 90 ;
多表查询
SELECT a. nickname, a. role, b. title, b. count from user as a, user_b as b;
嵌套查询
select * from user_b
where id= ( select id from user_b where count> 5 ) ;
查询头几条数据
select top 2 * from user_b;
删除
delete from user_b where id= 4 ;
更新
update user_b set title= "这是一条添加数据" where id= 4 ;
求和
select sum ( count) from user_b;
ps:sum ( 字段) 对字符串和时间无效
求平均值
select avg ( count) from user_b;
ps:avg ( 字段) 对字符串和时间无效
计数
select count ( * ) from user_b;
ps:count ( 字段名) 不包含NULL ;
求最大值
select max ( count) from user_b;
ps:字符串的话返回字母序最大的
数值返回数值最小值
求最小值
select min ( count) from user_b;
ps:字符串的话返回字母序最小值,
数值返回数值最小值
查询结果数限制
select * from user_b limit 1 ;
排序
select * from user_b order by count;
ps:默认从小到大排序
select * from user_b order by count desc ;
待完成...
union ( 并查询)
in ( 交查询)
group by ( 分组)
索引