创建表

create table t1(id int primary key auto_increment,username char(12) not null,sex enum('male','female') default 'male',hobby set('study','sing','eat','drink')
);create table t2(id int,name char(12));

insert into 表(字段,.......) values(值,........);insert into t1 values(1,'mike','male','sing,drink'),
(2,'ali','female','sing'),
(3,'amy','female','sing,drink,study'),
(4,'Gsir','male','drink');insert into t1(username,hobby) values('zhangsan','study');insert into t2(id,name) select id,username from t1;

mysql> delete from t2;  (如果有自增id  不会清除自增字段的offset值)

# show create table t1;               查看t1目前偏移量

mysql> delete from t1 where id = 3;

mysql> truncate table t1;

# 会清空表和自增字段的偏移量


update 表 set 字段=值 where 条件;

update 表 set 字段=值,字段=值 where 条件;

mysql> update t1 set id = 5,hobby = 'sing' where id  = 4;

select

select * from 表;

select 字段... form 表;

# 重命名

select 字段 as 新名字,... form 表;

select 字段 新名字,... form 表;

# 避免重复

select distinct post from  employee;

# 四则运算

mysql> select emp_name,salary*12 as annual_salary from employee;

# concat  拼接函数

mysql> select concat('a','b','c');

# 单表查询
create table employee(
id int not null unique auto_increment,
emp_name varchar(20) not null,
sex enum('male','female') not null default 'male', #大部分是男的
age int(3) unsigned not null default 28,
hire_date date not null,
post varchar(50),
post_comment varchar(100),
salary double(15,2),
office int, #一个部门一个屋子
depart_id int
);insert into employee(emp_name,sex,age,hire_date,post,salary,office,depart_id) values
('egon','male',18,'20170301','老男孩驻沙河办事处外交大使',7300.33,401,1), #以下是教学部
('alex','male',78,'20150302','teacher',1000000.31,401,1),
('wupeiqi','male',81,'20130305','teacher',8300,401,1),
('yuanhao','male',73,'20140701','teacher',3500,401,1),
('liwenzhou','male',28,'20121101','teacher',2100,401,1),
('jingliyang','female',18,'20110211','teacher',9000,401,1),
('jinxin','male',18,'19000301','teacher',30000,401,1),
('成龙','male',48,'20101111','teacher',10000,401,1),('歪歪','female',48,'20150311','sale',3000.13,402,2),#以下是销售部门
('丫丫','female',38,'20101101','sale',2000.35,402,2),
('丁丁','female',18,'20110312','sale',1000.37,402,2),
('星星','female',18,'20160513','sale',3000.29,402,2),
('格格','female',28,'20170127','sale',4000.33,402,2),('张野','male',28,'20160311','operation',10000.13,403,3), #以下是运营部门
('程咬金','male',18,'19970312','operation',20000,403,3),
('程咬银','female',18,'20130311','operation',19000,403,3),
('程咬铜','male',18,'20150411','operation',18000,403,3),
('程咬铁','female',18,'20140512','operation',17000,403,3)
;

mysql> select id,emp_name from employee;

mysql> select id,emp_name as name from employee;

mysql> select id,emp_name as name from employee;

# 避免重复

mysql> select distinct post from employee;

# 四则运算

mysql> select emp_name,salary*12 as annual_salary from employee;

# concat

mysql> select concat(emp_name,':',salary)from employee;

mysql> select concat_ws('|',emp_name,salary*12) as annual_salary from employee;

where

mysql> select * from employee where post != 'sale';

mysql> select * from employee where id < 10;

between...and

mysql> select * from employee where salary between 10000 and 14000;

in

mysql> select * from employee where salary in (10000,18000,200000);

模糊匹配

like

# % 通配符 任意长度的任意内容

mysql> select * from employee where emp_name like 'j%';

mysql> select * from employee where emp_name like '%j%';

mysql> select * from employee where emp_name like '%j';

# _ 通配符  一个长度的一个内容

mysql> select * from employee where emp_name like '%e_';

regexp

mysql> select * from employee where emp_name regexp '^j';

mysql> select * from employee where salary regexp '\d{4,5}';

not in     and   or

select * from employee where salary not in (10000,20000) and age = 18;

mysql> select * from employee where sex = 'male' and post = 'sale' or id < 5;

mysql表的增删改select 和 where相关推荐

  1. MYSQL表的增删改查进阶(下)

    MYSQL表的增删改查进阶 4. 查询 4.1 聚合查询 4.1.1 聚合函数 4.1.2 group by字句 4.1.3 having 4.2 联合查询 4.2.1 内连接 4.2.2 外连接 4 ...

  2. 2.MySQL表的增删改查(进阶)

    这里写目录标题 MySQL表的增删改查(进阶) 1.数据库约束 2.表的设计 3.新增 4.查询 4.1 聚合查询 4.2 联合查询 5.内容重点总结 MySQL表的增删改查(进阶) 1.数据库约束 ...

  3. MySQL表的增删改查(基础)

    MySQL表的增删改查(基础) 文章目录 MySQL表的增删改查(基础) 新增(`Create`) 查询(`Retrieve`) 更新(`Update`) 删除(`Delete`) 总结 注释:在SQ ...

  4. MySQL表的增删改查

    MySQL表的增删改查 CRUD 即增加(Create).查询(Retrieve).更新(Update).删除(Delete)四个单词的首字母缩写. 表的操作,是以一套记录为基本单位: 增.删只能是以 ...

  5. 数据库概论之MySQL表的增删改查1

    MySQL表的增删改查 1.MySQL表的CRUD 2.插入数据 2.1 语法 2.2 注意事项 3.查找语句 3.1 全列查找 3.2 指定列查询 3.3 指定查询字段为表达式 3.4 查询字段指定 ...

  6. 【MySQL系列】 MySQL表的增删改查(进阶)

    目录 ??前言 ??一.数据库约束 ???1.1 约束类型 ???1.2 null约束 ???1.3 unique约束 ???1.4 default约束 ???1.5 primary key 约束 ? ...

  7. php mysql表的增删改查,PHP 之Mysql增删改查操作案例

    1:user表: CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL, PR ...

  8. 【MySQL】(万字解析)MySQL表的增删改查(进阶-上)

    快速跳转✅ 1.数据库的约束 1.1 约束类型 1.2 NULL约束 1.3 UNIQUE:唯一约束 1.4 DEFAULT:默认值约束 1.5 PRIMARY KEY:主键约束 1.6 FOREIG ...

  9. MySQL表的增删改查--你都知道吗?

    文章目录 CRUD 查询 修改 删除 数据库约束 数据库的设计 插入查询的数据 聚合查询 分组查询 联合查询/多表查询(重点) 内连接与外连接 子查询 合并查询 注释:在SQL中使用 --(空格) + ...

最新文章

  1. 【硅谷牛仔】优步CEO,最倒霉的成功创业者 -- 特拉维斯·卡兰尼克
  2. NodeJs初学者经典入门解析
  3. python篮球-用Python把蔡徐坤打篮球视频转换成字符动画!
  4. miniGUI安装笔记(转)
  5. CVE-2015-0235: GHOST – A Critical Vulnerability in the Glibc Library
  6. Android官方开发文档Training系列课程中文版:支持不同的设备之支持不同的语言
  7. 雨林木风win11 64位安全旗舰版镜像V2021.09
  8. Golang的数组与切片——详解
  9. 为计算机构建安全方案,计算机科学系安全管理标准化建设实施方案
  10. 越南山寨QQ,我今天才知道,太山寨了!
  11. 安装idea(最新版IntelliJ IDEA)编译器(详细到每步)
  12. 台式电脑计算机图标打不开怎么办,电脑计算机图标打不开怎么办
  13. KiCad: 一个电子原理图设计和布局创建套件
  14. smss lsass http://laji.xrlyy.com病毒解决办法
  15. win10永久自动更新服务器,四种方法关闭win10专业版自动更新
  16. 详解ARM的AMBA设备中的DMA设备(Linux驱动之DMA)
  17. 跑步听歌用哪种耳机更好?精挑五款适合跑步听歌的耳机分享
  18. python 整合_python的资源整合
  19. 鸿蒙与北斗星云手机,为何其他国产手机不接入鸿蒙?王成录一语道出真谛
  20. [hihoCoder] 区域周长 解题报告

热门文章

  1. ArcGIS聚合容差修正两个shapefile 之间的数字化错误
  2. 手机网站常用的推广方式有哪些
  3. 【转】计算机词汇简繁体对照表
  4. MYSQL的一知半解
  5. 7.Python 文件I/O
  6. VR直播营销需求增加,数据模块为我们铺路
  7. html5实现定位签到,H5+百度地图实现移动端考勤定位打卡
  8. 几何画板真的这么好用吗
  9. C++:给定一个二维点集,找到所有的整体对称轴
  10. 不再纠结devDependencies与dependencies