mysql基本操作

增:insert into 表名(id,name) values(0,'尹当')

删:delete from [表名] where ([条件]);

改:update [表名] set [修改内容如name = 'Mary'  列名='新的值,非数字加单引号'] where [条件如:id=3];

查:select 查询字段 from 表名 where 条件

alter table 表名 add primary key(字段名)   设置主键

从别的表格复制一行插入到目标表格:insert into [目标表名] select from [复制表名] where [条件];

2张表格关联:语法 表1 left join 表2 on 条件

例子:select 表1.* 表2.* from 表1 left join 表2 on [条件,如表1.id = 表2.id]

1.内连接:取的两个表的(有能连接的字段)的交集,即字段相同的。利用内连接可获取两表的公共部分的记录, 
select * from A,B where A.id=B.id 
与 Select * from A JOIN B ON A.id=Bid的运行结果是一样的。 

2.外连接:左右连接。 

外连接分为两种,一种是左连接(Left JOIN)和右连接(Right JOIN) 

(1)左连接(Left JOIN...ON...):左表为基准,返回左表行

 左连接是已左边表中的数据为基准,若左表有数据右表没有数据,则显示左表中的数据右表中的数据显示为空

计算多少条数据

SELECT count(*) FROM 表

排序

ORDER BY

DESC

去重

DISTINCT

模糊查询

LIKE '%test%'

MySQL 索引

drop table 字段

(case when cj>=80 then '优秀'

when cj >=60 then '及格' else '不及格' end)

sql题目https://blog.csdn.net/hwq1987/article/details/6670300

原文地址:https://www.cnblogs.com/jiaoyang77/p/7513060.html