查询所有的列
SELECT * FROM class;
SELECT id,name FROM class;
给列起别名
SELECT name AS 姓名,id AS ID FROM class;
只显示不同的记录
SELECT DISTINCT name FROM class;
在查询时执行计算
SELECT ename AS 姓名,(salary+500)*12+5000 AS 年薪 FROM emp;
SELECT name AS 姓名,(yuwen+shuxue)AS 总分 FROM class;
查询结果集的排序
SELECT * FROM class ORDER BY yuwen ASC; #升序排序
SELECT * FROM class ORDER BY yuwen DESC; #降序排序
SELECT * FROM class ORDER BY yuwen DESC,shuxue DESC;
#先按语文,后按数学
条件查询
= <= > < = !=(不等于)
SELECT * FROM class WHERE name=“yy”;
SELECT * FROM class WHERE name!=“yy”;
SELECT * FROM class WHERE yuwen>=85;
SELECT * FROM class WHERE yuwen>=85 AND yuwen<100;
SELECT * FROM class WHERE yuwen>=90 OR shuxue>=90;
limit限制
SELECT * FROM class WHERE yuwen>=5 LIMIT 2, 3;#跳过前2个,获取3个(第3-5个)
转载:https://blog.csdn.net/weixin_43745003/article/details/101455897