mysql--基本语句1-基本查询
1 create table dis_exam( 2 id int primary key auto_increment not null , 3 student_name varchar(20) not null , 4 exam_python double default 0 , 5 exam_linux double default 0 , 6 exam_mysql double default 0 7 ); 8 9 insert into dis_exam values (1,'1号', 98, 98, 98), 10 (2,'2号',35, 98, 67), 11 (3,'3号',59, 59, 62), 12 (4,'4号', 88, 89, 82), 13 (5,'5号', 88, 98, 67), 14 (6,'6号', 86, 100, 55); 15 16 insert into dis_exam(student_name) values ('1号'), ('2号'), ('1号'); 17 18 use learn_db; 19 20 # 查询所有 select * from + 表名 21 select * from dis_exam ; 22 23 # 去重 select distinct + 字段名 from 表名 24 select distinct student_name from dis_exam ; 25 26 # 查询一到多个字段的值 select 字段名1,字段名2,...,字段名n form + 表名 27 select student_name from dis_exam ; 28 select id, student_name from dis_exam ; 29 30 # 查询时显示(临时更改, 一般用于数值型数据) 31 select student_name, exam_linux from dis_exam ; 32 select student_name, exam_linux+10 from dis_exam ; 33 34 # 查询临时显示表头(别名) select +字段名 as + 别名 from 表名 35 select student_name as name from dis_exam ; 36 37 # 条件判断 38 /* 39 比较运算符: > < >= <= <> != 40 between x and y -->在x到y之间 41 in(x, y, z) -->值是x或y或z 42 line '张三%' --> 等于..., %表示通配符, %->表示任意多的字符; _->表示一个字符 43 逻辑运算符: and or not 44 45 is null -->查询空值 46 47 */ 48 select * from dis_exam where exam_linux>60 ; 49 select * from dis_exam where exam_python!=88 ; 50 select * from dis_exam where exam_mysql between 80 and 100 ; 51 select * from dis_exam where exam_python in (88, 98) ; 52 select * from dis_exam where student_name like '1%' ;
本文来自博客园,作者:关于段主任的一切,转载请注明原文链接:https://www.cnblogs.com/fairylandfuture/p/15068105.html