[innoVation]SQL语句基础2 2017.11.16

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) 指定看那几条记录。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值