MySQL 入门笔记(三)

MySQL 入门笔记(三)

创建

CREATE TABLE IF NOT EXISTS student ( 
	id INT,
	name VARCHAR(20),
	age INT,
	sex VARCHAR(10),
	english INT,
	math INT
);

修改

UPDATE student set id = 1 WHERE id = 10;
UPDATE student set english = NULL WHERE id = 1;

插入

INSERT INTO student (id,name,age,sex,english,math) VALUES (1,'黎明',33,'男',99,98);
INSERT INTO student (id,name,age,sex,english,math) VALUES (2,'刘德华',34,'男',91,93);
INSERT INTO student (id,name,age,sex,english,math) VALUES (3,'张学友',32,'男',99,99);
INSERT INTO student (id,name,age,sex,english,math) VALUES (4,'郭富城',30,'男',93,98);
INSERT INTO student (id,name,age,sex,english,math) VALUES (5,'张国荣',40,'男',100,100);
INSERT INTO student (id,name,age,sex,english,math) VALUES (6,'梅艳芳',37,'男',99,100);
INSERT INTO student (id,name,age,sex,english,math) VALUES (7,'邱淑贞',30,'女',90,90);

删除

  1. 删除表
DROP TABLE stu;
  1. 删除表中指定数据
DELETE FROM student  WHERE id = 1;
  1. 清空表
DELETE FROM student
TRUNCATE TABLE student;

查询

  1. 查询表
SELECT * FROM student;
  1. 查询指定列
SELECT name,age FROM student;
  1. 去重查询
SELECT DISTINCT english,math FROM student
  1. 条件查询
SELECT * FROM student WHERE math > 90 ;
SELECT * FROM student WHERE math > 90 AND english > 98;
SELECT * FROM student WHERE math > 90 OR english > 98;
SELECT * FROM student WHERE math IN (90,100);

SELECT * FROM student WHERE math BETWEEN 95 AND 100;

SELECT * FROM student WHERE english IS NULL;
  1. 模糊查询
SELECT * FROM  student WHERE name LIKE  '_学%';
SELECT * FROM  student WHERE name LIKE  '_学_';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值