SQL语句执行顺序
例如:
select username,password,email from t_user where uid = "1";
sql语句的执行顺序:先执行from,查到数据来源表t_user中的数据,再执行where,对查询数据做第一次过滤,留下uid=“1”的数据,最后执行select,查询各个字段的值。
1. show databases;右键执行查询
查询结果
2. create database companydb;创建一个数据库
3.新建表插入数据并查询
4.查询结果去重 加关键字distinct
select distinct manager_id from t_employees;
5. 排序查询
select 列名 from 表名 order by 排序列[排序规则]
排序规则
ASC 对前面排序做升序排序
DESC 对前面排序做降序排序
例题:
#根据工资升序排序
SELECT employee_id,salary FROM t_employees ORDER BY salary ASC;
例题2
工资升序,id也升序
#根据工资降序排序,同时经理id相同的也降序排序
SELECT employee_id,salary FROM t_employees ORDER BY salary ASC,employee_id ASC;