select {
[distinct|all]columns|*}
[into table_name]from {
tables| views | other select}
[where conditions][groupby conditions][having conditions][orderbycolumns];select 子句:用于选择数据表、视图中的列;
into 子句:用于将原表的结构和数据插入新表中;
from 子句:用于指定数据来源,包括表,视图和其他select语句;
where 子句:用于对检索的数据进行筛选;
groupby 子句:用于对检索结果进行分组显示;
having 子句:用于从使用groupby子句分组后的查询结果中筛选数据行;
orderby 子句:用于对结果集进行排序(包括升序和降序);
简单查询
1.检索所有的列:*
eg:select*from dept;2.检所指定的列:column_name
eg:select job,ename,empno from emp;3.带有表达式的select语句:+-*/()
eg:select sal*(1+0.1),sal from emp;4.为列指定别名:as
eg:select empno as"员工编号",ename as"员工名称",job as"职务"from emp;select empno "员工编号",ename "员工名称",job "职务"from emp;5.显示不重复记录:distinct
eg:selectdistinct job from emp;
筛选查询
select columns_list
from table_name
where conditional_expression;
column_list:字段列表;
table_name:表名;
conditional_expression:筛选条件表达式;
1.比较筛选:=,!=或<>,>,<,>=,<=
eg:select empno,ename,sal from emp where sal>1500;
A{operator}any(B):表示A与B中的任何一个元素进行operator运算符的比较,只要有一个比较值为true,就返回数据行;
A{operator}all(B):表示A与B中的所有元素进行operator运算符的比较,只有与所有元素比较值都为true,才返回数据行;
eg:select empno,ename,sal from emp where sal<>all(3000,950,800