用数据运算符创建数字和日期数据的表达式
SELECT 列名 AS 列别名 FROM 表名 WHERE 条件;
在select子句中用distinct关键字除去相同的行
SELECT 列名 AS 列别名 FROM 表名 WHERE 条件;
查询 employees 表,薪水在 3000-8000 之间的雇员ID、名字与薪水。
select employee_id,last_name,salary fromemployees where salary between 3000 and 8000;
查询 employees 表,找出薪水是 5000,6000,8000 的雇员ID、名字与薪水。
select employee_id,last_name,salary fromemployees where salary between 3000 and 8000;
查询 employees 雇员名字的第二个字母是 e 的雇员名字。
select last_name from employees wherelast_name like '_e%';
NULL 条件,包括 IS NULL 条件和 IS NOT NULL 条件。
找出 emloyees 表中那些没有佣金的雇员雇员ID、名字与佣金。
select employee_id,last_name,commission_pctfrom employees where commission_pct is null;
找出 employees 表中那些有佣金的雇员ID、名字与佣金。
select employee_id,last_name,commission_pct from employees where commission_pct is not null;
查询 employees 表中雇员名字中不包含 u 的雇员的名字。
select last_name from employees where last_name not like '%u%';
使用圆括号改变优先规则
如果使用了 ORDER BY 子句,它必须位于 SQL 语句的最后。
查询 employees 表中的所有雇员,显示他们的ID、名字与薪水,并按薪水升序排序。 select employee_id,last_name,salary from employees order by salary asc;
以升叙排序显示 DEPARTMENT_ID 列,同时以降序排序显示SALARY 列。
select department_id,salary from employees order by department_id asc ,salary desc
原文链接:https://juejin.cn/post/7120534820446437390
留言与评论(共有 0 条评论) “” |