插入:insert intotable1(field1,field2) values(value1,value2)
查找:
指定显示某一字段
selectxing_ming from xue_sheng;
模糊查询
select* from table1 where field1 like ’%value1%’ ---like的语法很精妙,查资料!
满足多条件查询
select * from xue_sheng where xing_minglike '李%' and xing_bie='女';
进行排序查询
order by 字段名 desc(降序) 或者 asc(默认升序)
select * fromxue_sheng order by fen_shu desc;
更新:update table1 setfield1=value1 where 范围
指定id等于3的记录进行更新
update xue_sheng setxing_bie='男' where id=3;
如果没有 where 指定条件,则全部进行更新
update xue_sheng setxing_bie='女';
删除:delete from table1 where范围
不过我们一般加入 where 条件进行删除, 否则将会把表的内容全部清空。
总数:select count * astotalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
分组查询:
selectxing_bie,sum(fen_shu) from xue_sheng group by xing_bie;
join on 表连接
selectxing_ming,ban_ming from xue_sheng x join ban_ji b on x.bj_id=b.id;
子查询,又叫嵌套查询 in() 或者 not in()
select * from xue_sheng where bj_id in( 1 ,2,3);