三大数据类型:字符串:char、varchar。数值:int、float。日期:date、time、datetime、timestamp
增:insert into 表名(字段名1,字段名2)values(值1,值2);
删:delete from 表名 where 字段名=字段指定的值;
改:update user set gender=”女” where id=4;
查:基本查询:select * from 表名;
查询字句:where:select * from u where id=1;
排序:select * from u order by id; select * from u order by id desc;
分组:select * from u group by id;
去重:select distinct name form u;
内连接:select * from web w inner join web2 w2 on w.id=w2.id;
左连接:select * from web w left join web2 w2 on w.id=w2.id;
右连接:select * from web w right join web2 w2 on w.id=w2.id;
全连接:左连接 union 右连接
select * from web w left join web2 w2 on w.id=w2.id
union
select * from web w right join web2 w2 on w.id=w2.id;
三表关联查询:
select st.*,sc.*,su.* from stu st
inner join score sc on st.no=sc.no
left join sub su on sc.subno=su.subno
where st.no>0;
子查询,单值
select * from emp where salary > (select salary from emp where emp_name=”王强”);查询工资大于王强的数据