[innoVation]SQL语句基础2 2017.11.16
2017-11-16 11:16
423 查看
select * from 表名 where 列名 = ' '
select * from 表名 where 列名 is null
注意: null 为 列名 is null , ' ' 为 列名 = ' '。
范围内的取值
select * from 表名 where 列名 >= 1 and 列名 <= 9
between and 包括两个端点
select * from 表名 where
列名 BETWEEN 7369 and 7566
order by 排序
order by语句用于对结果集进行排序
order by 语句用于根据指定列对结果集进行排序
order by 语句默认按照升序对记录进行排序
升序asc 降序为 desc
select empno from emp ORDER BY empno DESC 降序
select empno from emp ORDER BY empno ASC 升序
LOWER()函数
select LOWER(ename)小写名称,ename from emp
UPPER()函数
select UPPER(LOWER(ename)) from emp
LENGTH()函数
select LENGTH(ename) , ename from emp
COUNT()函数 AVG()函数 MAX()函数 MIN()函数 SUM()函数
select count(*) 员工人数, avg(sal) 平均工资, MAX(sal)最高工资 , MIN(sal)最低工资 ,SUM(sal) 总合 from emp
GROUP BY 分组
注意:分组后过滤条件要写在HAVING后
select deptno,COUNT(*) from emp GROUP BY deptno HAVING deptno > 10
所有主函数不能直接使用,只能查询一次后才能使用。
select * from emp where sal >(select AVG(sal) from emp)
SELECT * from emp where empno in(select empno from emp where empno > 7500)
联表查询
用逗号联表查询后,and后跟筛选条件
elect e.*,d.dname from emp e, dept d where e.deptno = d.deptno and sal > 1000
联表条件写在ON后,where后跟筛选条件
select e.*,d.dname from emp e INNER JOIN dept d ON e.deptno = d.deptno where e.sal > 1000
LIMIT
可以强制select语句返回指定的记录数。
select * from emp LIMIT 0 ,10
select * from user11 where userId in (2,3,4) 指定看那几条记录。
select * from 表名 where 列名 is null
注意: null 为 列名 is null , ' ' 为 列名 = ' '。
范围内的取值
select * from 表名 where 列名 >= 1 and 列名 <= 9
between and 包括两个端点
select * from 表名 where
列名 BETWEEN 7369 and 7566
order by 排序
order by语句用于对结果集进行排序
order by 语句用于根据指定列对结果集进行排序
order by 语句默认按照升序对记录进行排序
升序asc 降序为 desc
select empno from emp ORDER BY empno DESC 降序
select empno from emp ORDER BY empno ASC 升序
LOWER()函数
select LOWER(ename)小写名称,ename from emp
UPPER()函数
select UPPER(LOWER(ename)) from emp
LENGTH()函数
select LENGTH(ename) , ename from emp
COUNT()函数 AVG()函数 MAX()函数 MIN()函数 SUM()函数
select count(*) 员工人数, avg(sal) 平均工资, MAX(sal)最高工资 , MIN(sal)最低工资 ,SUM(sal) 总合 from emp
GROUP BY 分组
注意:分组后过滤条件要写在HAVING后
select deptno,COUNT(*) from emp GROUP BY deptno HAVING deptno > 10
所有主函数不能直接使用,只能查询一次后才能使用。
select * from emp where sal >(select AVG(sal) from emp)
SELECT * from emp where empno in(select empno from emp where empno > 7500)
联表查询
用逗号联表查询后,and后跟筛选条件
elect e.*,d.dname from emp e, dept d where e.deptno = d.deptno and sal > 1000
联表条件写在ON后,where后跟筛选条件
select e.*,d.dname from emp e INNER JOIN dept d ON e.deptno = d.deptno where e.sal > 1000
LIMIT
可以强制select语句返回指定的记录数。
select * from emp LIMIT 0 ,10
select * from user11 where userId in (2,3,4) 指定看那几条记录。
相关文章推荐
- [innoVation]SQL语句基础 2017.11.15
- SQL语句收集--基础
- java基础巩固---jdbc接口PreparedStatement执行sql语句
- 基础SQL语句
- Oracle(PL/SQL编程基础(PL/SQL程序块与PL/SQL语句)、异常、游标、数据类型)
- T-SQL语句基础
- sql基础语句02
- MySQL阶段二——sql语句基础(3)
- SQL基础语句总结
- sql基础语句01
- Oracle PL/SQL语句基础学习笔记(上)
- sql基础语句大杂烩
- SQL基础实用语句
- Sql基础语句1
- 数据库基础及T-SQL语句
- 15个初学者必看的基础SQL查询语句
- SQL基础--基础语句和运算
- SQL 基础:Select语句,各种join,union用法
- SQL基础语句
- SQL基础语句总结