*# DQL语言
显示表结构 desc table;
查询常量值
select 100;
select 'python';
查询表达式(四则运算)
select 100*98;
查询函数
seelct version();
起别名
/* 便于理解 如果要查询的字段存在重名,起别名可区分 */
方式一
select 100*98 as 结果;
select first_name as 姓,last_name as 名 from employees;
方式二
select 100*98 结果;
select first_name 姓,last_name 名 from empl0yees;
案例 查询salary 显示呢结果为out put(存在关键字)
select salary as 'out put' from employees;
去重
案例:查询员工表中涉及到的所有部门编号
select distinct department_id from employees;
‘+’的作用 案例:查询员工的姓和名并连接为一个字段
/*
mysql中‘+’作为运算符
两个数皆为数值型
其中一方为字符型,则将字符转化为数值型继续运算
若转换失败,则字符转为为0
其中一方为null,则结果肯定为null
*/
拼接函数:
concat(str1,str2...)
select concat(first_name,last_name) as 姓名 from employees;
条件查询
select * from table where 条件;
1、条件表达式筛选:
条件运算符
3、逻辑表达式筛选
逻辑运算符:&& || ! 或者and or not
3、模糊查询
like
between
in
is null
安全等于:<=> 可以判断null值和普通值
排序
select 查询列表
from table
where 筛选条件
order by 排序列表 asc\desc
多字段排序
select 查询列表
from table
where 筛选条件
order by 排序列表 asc\desc,排序列表 asc\desc
注:asc代表的是升序,desc代表的是降序,默认是升序 order by 子句中可以支持单个字段、多个字段、表达式、函数、别名 order by 一般放在查询语句的最后面,limit子句除外
DML语言(增 删 改) #DDL语言 #TCL语言