1.展示所有列语法
select * from table; #table表示表名
示例:
select * from a
2.展示指定列语法
select column1, column2, ... from table; #column1,column2列名
示例:
select subject, Score from a;
3.展示满足条件的数据(where)
select * from table where condition; # condition 筛选条件 select column1,column2 from table where condition; # condition 筛选条件
3.1 筛选条件:比较运算符,=、>、<、!=、>=、<=、<>
示例:
查询大于某个值的数据
select * from a WHERE Score >90
select No, subject from a WHERE Score > 90;
查询不等于某个值的数据
select * from a WHERE Score <>90;
select No, subject from a WHERE Score != 90;
3.2 筛选条件:between and
示例:
查询介于某个值之间的数据
select * from a WHERE Score BETWEEN 80 and 90;
3.3筛选条件:逻辑运算,and, or, not
示例:
查询小于某个或大于某个值的数据
select * from a WHERE Score<80 or Score>90;
3.4筛选条件:空值判断,is NULL 、is not NULL
示例:
查询不为空的数据
select * from a WHERE Score is not NULL;
3.5 筛选条件:模糊匹配, like
示例:
查询带有语的科目数据
select subject from a WHERE subject like "语%"; #以语开头的数据
select subject from a WHERE subject like "%语"; # 以语结尾的数据
select subject from a WHERE subject like "%语%"; # 含有语的数据
3.6筛选条件:存在与不存在,in、not in
示例:
查询不为数学、语文的数据
select * from a WHERE subject not in ("数学", "语文");
4.查询结果按某个字段升序、降序排序(order by)
语法:
select * from table order by column1 DESC; #DESC 降序排序 select column1,column2,column3 from table where conditon order by column1 ASC; # 升序排序,不写默认升序
示例:
select * from a ORDER BY Score ASC;
select subject, Score from a WHERE subject LIKE "%语%" ORDER BY Score DESC;
标签:语句,示例,Score,SELECT,SQL,table,WHERE,select,subject From: https://www.cnblogs.com/mian-1122/p/16992792.html