数据操作
简单查询
--select * from 表名
select * from ylt_sys_user
添加一行数据
主键自增长,可以用0或者null代替
--insert into 表名 values(...)
insert into fe_ylt_super_user
values(0,18011111111,123456)
--使用表字段进行添加的时候,可以不按照顺序,到需要一一匹配
insert into fe_ylt_super_user(id,universal_code,phone) values (0,123456,18011111111)
添加多行数据
--方式一:写多条insert语句,多条之间用英文分号分隔
insert into fe_ylt_super_user(id,universal_code,phone) values (0,1,18011111112);
insert into fe_ylt_super_user(id,universal_code,phone) values (0,2,18011111113);
insert into fe_ylt_super_user(id,universal_code,phone) values (0,3,18011111114);
--方式二:通过一条insert语句插入多条数据,数据间用逗号分隔(一组一组的分割开)
insert into fe_ylt_super_user values (0,18011111112,1),(0,18011111113,2),(0,18011111114,3);
修改数据
--修改数据
--update 表名 set 字段名1=值1,字段名2=值2 ...where 条件
--修改phone为18011111114的验证码为123
update fe_ylt_super_user set universal_code ="123" where phone = "18011111114"
--删除数据
--delete from 表名 where 条件
--删除phone为18011111114的用户
delete from fe_ylt_super_user where phone ="18011111114"
其他删除数据的方式:
truncate table 表名
清除表里的所有数据,但是表结构会保留,自增字段从1开始
drop table 表名(删除数据表,包括表数据和表结构)
数据查询操作
查询部分字段的值
--select 字段名1,字段名2...from 表名(查询的为一部分字段信息)
select gravida_id ,end_mode from fe_ylt_monitoranalysis limit 1,10
取别名
--给表取别名
select 别名.字段名1,别名.字段名2 from 表名 as 别名
select jc.gravida_id,jc.end_mode from fe_ylt_monitoranalysis as jc limit 1,10
--给字段取别名
select gravida_id as 孕妇id,end_mode as 结束标志 from fe_ylt_monitoranalysis limit 1,10
去重
--select distinct 字段名1,字段名2...from 表名
--按照孕妇id去重
select distinct gravida_id from fe_ylt_monitoranalysis limit 1,10
条件查询
--select 字段名1,字段名2...from 表名 where 条件
select * from fe_ylt_monitoranalysis where gravida_id = "600061"
比较运算符
比较运算符:大于(>),等于(=),小于(<),大于等于(>=),小于等于(<=),不等于(<>或!=)
--查询600072的年龄
select age from fe_ylt_gravida where id = "600072"
--查询20岁以下的用户
select * from fe_ylt_gravida where age <20
--查询ip不在南京的用户
select * from fe_ylt_gravida where city_ip != "南京市"
逻辑运算符
逻辑运算符:and(且,同时符合对应的条件),or(或,符合其中的一个条件),not(非,不符合该条件)
--查询年龄大于30岁的江苏用户
select * from fe_ylt_gravida where age > 30 and province = "江苏省"
--年龄大于30岁或者江苏用户
select * from fe_ylt_gravida where age > 30 or province = "江苏省"
--查询非江苏省的用户
select * from fe_ylt_gravida where province != "江苏省"
select * from fe_ylt_gravida where not province = "江苏省"
模糊查询
模糊查询:like关键字
%:匹配任意个字符
_:匹配任意单个字符
一般like关键字只用来匹配字段类型为字符串的
--查询名字带测试开头的用户
select * from fe_ylt_gravida where true_name like '测试%'
--查询名字是测试且三个字的用户
select * from fe_ylt_gravida where true_name like '测试_'
--查询名字中包含小的用户
select * from fe_ylt_gravida where true_name like '%小%'
--查询用户名为两个字的用户
select * from fe_ylt_gravida where true_name like '__'
--查询id为72结尾的用户
select * from fe_ylt_gra