找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
本帖最后由 武汉11期杜潮 于 2022-1-17 21:57 编辑

数据类型
int   整型 最大存储为3434343443 10位
bigint 长 整型 最大存储为3434343443 11位
warchar 存字符串 要用引号,双引号
date  时间 2001 3 9
float 小数点,浮点
常见的约束有哪些
priamary key 主键约束,字段值必须是唯一不能重复
auto increment 自增长约束
not null 非空约束
default 默认值约束
foregin key 外键约束

对表 的结构的修改
desc dc1 查看表的结构
alter table dc1 rename dc2 将dc1 改成dc2
alter table dc1 change id sid
alter table dc1 change id sid int(10)
alter table dc1 add id2 int(10) 增加id2这个字端

alter table dc1 add id6after int(10)after phone;.就id6,添加到phone后面
alter table  dc1 drop id2;删除字段
alter table  dc1 drop id2,drop id3;同时多个字段
drop table dc1 删除表
对表的操作
增加==insert into dcb(name)values("duchao");增加一个
insert into dcb(name)values("duchao"),(duchao1),(duchao2);增加多个
0不是NULL null表示空 0是一个值

查 select * from 表格

select * from dcb where name="duchao";查name=duchao的所有数据
select id from dcb where name="duchao";查询name=duchao的id
select  id  phone from dcb where name="duchao";查询name=duchao的id phone
select *from dcb; 查看全表数据
select  name from dcb; 查询dcb 中的name的
select id name from dcb;查询dcb表中name id
select *from dcb where name="duchao";查询表中name为duchao的数据
select *from dcb where phone!=12233333333;在表单中查询phone不为12333333333的数据
select *from dcb where phone<>12233333333;
select *from dcb where class=100 and phone=1233333333;在表单中查询class=100和phone=1233333333的数据
select *from dcb where class=100 or phone=1233333333;在表单中查询class=100或phone=1233333333的数据
select *from dcb where id>=2 and id>=5;在表单中查询id2-5的数据
select *from dcb where id between 2 and 5;
select *from dcb where class in (100,101)查询class为100和101的数据
select *from dcb where class not in (100,101)查询class不为100和101的数据
select*from dcb where time is null;查询time中为空的数据
select*from dcb where time is not null;查询time中不为空的数据
select*from dcb where name like "%dc%";查询所有字段包含dc的数据
select*from dcb where name like "lao%";lao开头老结尾
select*from dcb where name like "%lao";lao结尾的数据
select*from dcb name limit 1,4;查询1-5行数据(limit m,n m为下标 n为行数)
select*from dcb name limit 0,5;查询前5行数据

update dcb4 set class=101 where id=1;
update dcb set phone =12233333333 where id=2;将ID=2 的phone改为1233333333
update dcb set phone =12233333333 where id>=2;将id>=2 的phone改为1233333333

delete from dcb where id=5;删除id=5的数据
delete from dcb;删除全表格数据
drop table dcb;删除表数据和结构
truncate dcb ;删除表的数据

排序
从小到大   升序
select*from dcb order by class esc;
从大到小 降序
select*from dcb order  by class desc;
select*from dcb group by class;通过class字段来分组
select calss, count (*)  from dcb group by class;通过class字段来分组,然后求出每组的人数
select calss, count (*)  from dcb group by class having class is not null;通过class字段来分组,class不为空,然后求出每组的人数

常用的聚合函数
count()统计   select count(*) from dcb; 统计dcb表中数据条数
sum()  求和  select sum(id) ffrom dcb where class=101;求class为101的数据id之和
avq()平均值  select avq(id) from dcb where class=101;求class为101的id的平均值
max()最大值 select max(Id)from dcb;dcb中的id最大值
mix()最小值 select mix(id) from dcb;dcb中的id最小值
distinct  去重select distinct(id) from dcb;dcb中的id重复数据
分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册