1.展示所有列语法
select * from table; #table表示表名
示例:
select * from a
2.展示指定列语法
select column1, column2, ... from table; #column1,column2列名
示例:
select subject, Score from a;
![](/i/l/?n=23&i=blog/1973860/202212/1973860-20221220111614231-2144227169.png)
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;
![](/i/l/?n=23&i=blog/1973860/202212/1973860-20221220113007884-1690453177.png)
查询不等于某个值的数据
select * from a WHERE Score <>90;
select No, subject from a WHERE Score != 90;
![](/i/l/?n=23&i=blog/1973860/202212/1973860-20221220142215791-813333452.png)
3.2 筛选条件:between and
示例:
查询介于某个值之间的数据
select * from a WHERE Score BETWEEN 80 and 90;
![](/i/l/?n=23&i=blog/1973860/202212/1973860-20221220143630769-1054245097.png)
3.3筛选条件:逻辑运算,and, or, not
示例:
查询小于某个或大于某个值的数据
select * from a WHERE Score<80 or Score>90;
![](/i/l/?n=23&i=blog/1973860/202212/1973860-20221220144226913-1263676811.png)
3.4筛选条件:空值判断,is NULL 、is not NULL
示例:
查询不为空的数据
select * from a WHERE Score is not NULL;
![](/i/l/?n=23&i=blog/1973860/202212/1973860-20221220145642106-494037333.png)
3.5 筛选条件:模糊匹配, like
示例:
查询带有语的科目数据
select subject from a WHERE subject like "语%"; #以语开头的数据
select subject from a WHERE subject like "%语"; # 以语结尾的数据
select subject from a WHERE subject like "%语%"; # 含有语的数据
![](/i/l/?n=23&i=blog/1973860/202212/1973860-20221220150906725-658941258.png)
3.6筛选条件:存在与不存在,in、not in
示例:
查询不为数学、语文的数据
select * from a WHERE subject not in ("数学", "语文");
![](/i/l/?n=23&i=blog/1973860/202212/1973860-20221220152121641-908050691.png)
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;
![](/i/l/?n=23&i=blog/1973860/202212/1973860-20221220155821490-1492259328.png)
标签:语句,示例,Score,SELECT,SQL,table,WHERE,select,subject From: https://www.cnblogs.com/mian-1122/p/16992792.html