MySql基础篇
数据操纵语言DML
INSERT INTO student(NAME,sex,birthday,grade,score,phone,address,reg_time)
VALUE('tom','男','2000-1-2',1,98,'15929101866','xian',NOW())
INSERT INTO student SET NAME='张三',sex='男',birthday='2020-1-3',grade=2,score=97,phone='15959421585',address='陕西',reg_time=NOW()
INSERT INTO student(NAME,sex,birthday,grade,score,phone,address,reg_time)
VALUES('李四','男','2000-1-2',3,98,'15929101899','咸阳',NOW()),
('王五','女','2000-1-4',3,98,'15929101888','咸阳',NOW()),
('李六','男','2000-1-5',3,98,'15929101877','咸阳',NOW())
INSERT INTO stu(num,NAME,sex,birthday,grade,score,phone,address,reg_time)
SELECT * FROM student
UPDATE student SET NAME = '李四',sex='男'
UPDATE student SET NAME = '赵六',sex='女' WHERE num =2233
DELETE FROM student WHERE num = 2237
TRUNCATE TABLE student
ALTER TABLE student MODIFY num INT AUTO_INCREMENT
DQL数据查询语句
SELECT 100
SELECT 10+10
SELECT grade+1 FROM student
SELECT VERSION()
SELECT NOW()
SELECT * FROM student
SELECT num,NAME,sex FROM student
SELECT DISTINCT sex FROM student
SELECT grade+score FROM student
SELECT grade+1 FROM student
SELECT LENGTH(NAME) FROM student
SELECT CHAR_LENGTH(NAME) FROM student
SELECT CONCAT ('aa','bb','cc')
SELECT CONCAT (NAME,'是',sex) FROM student
SELECT UPPER(NAME) FROM student
SELECT UPPER('abc')
SELECT UPPER('ABC')
SELECT SUBSTRING(NAME,1,1) FROM student
SELECT INSTR(NAME,'o') FROM student
SELECT TRIM(NAME) FROM student
SELECT TRIM('o' FROM NAME) FROM student
SELECT LPAD(NAME,6,'z') FROM student
SELECT REPLACE(NAME , 'a','z') FROM student
SELECT
CASE WHEN score>=90 THEN 'A' ELSE 'B' END FROM student
SELECT
NAME,
(CASE WHEN score>=90 THEN 'A'
WHEN score>=80 AND score<90 THEN 'B'
WHEN score>=70 AND score<80 THEN 'C'
ELSE 'D'
END ) score
FROM student
SELECT IFNULL(phone,'未登记手机号') Moblie FROM student
SELECT IFNULL(phone,NAME) Moblie FROM student
SELECT IF(score>=90,'优秀','良好')score FROM student
SELECT ROUND(5.9)
SELECT CEIL(5.4)
SELECT FLOOR(5.9)
SELECT TRUNCATE(5.5363,2)
SELECT MOD(10,3)
SELECT RAND()
SELECT NOW()
SELECT CURDATE()
SELECT CURTIME()
SELECT YEAR(reg_time ) FROM student
SELECT MONTH(reg_time ) FROM student
SELECT STR_TO_DATE('1999-5-23','%Y-%m-%d')
SELECT DATE_FORMAT(reg_time,'%Y年%m月%d日')m FROM student
SELECT COUNT(*),DATE_FORMAT(reg_time,'%Y年%m月%d日')m FROM student GROUP BY m
SELECT DATEDIFF(reg_time,NOW()) FROM student
SELECT SUM(score) FROM student
SELECT SUM(DISTINCT score) FROM student
SELECT AVG(score) FROM student
SELECT MAX(score) FROM student
SELECT MIN(score) FROM student
SELECT COUNT(*) FROM student
SELECT COUNT(DISTINCT score) FROM student