数据库基础知识

DQL:查询语言
DML:数据操作
DDL:数据定义

  1. dual表
    是系统表,因为数据库语句必须完整,实际没有意义
    select 1+2 from dual
  2. 别名
    select user_id “id”,user_name name,user_phone as “phone” from user_tab;
  3. 链接
    select t.name ||‘的电话是’||t.phone from user_tab “t”;
  4. 匹配
    模糊匹配%or_(一位)
    id like _a%(第二位为a)
  5. 去重
    select distinct job from emp;
  6. and和or,in(),not()
    and优先于or
    where name in (‘张三’,’李四’);
    where not(name like ‘张%’);
  7. 排序
    asc 升序(默认)
    desc 降序
    order by name desc,user_id “id” asc;
  8. rownum
    1.只支持<和<=(=1和>=1的意思是1,额外支持)
    2.必须从第一列开始
    exp:
    显示后十条:
    select * from (select * from emp order by rownum desc) where rownum <11;
    显示5-10条:
    select * from (select rownum r,name from emp where rownum <11) “s” where s.r >5 ;
  9. 集合函数
    不可用于查询条件,除了count(),只能用having
    count(),max(),min(),avg(),sum(),sum()/count()
  10. 字符函数
    upper()大写
    lower()小写
    initcap()首字母大写
    sbustr(‘ABCdef’,4,6) def
    sbustr(‘ABCdef’,1,1) A
    sbustr(‘ABCdef’,0,1) A
    sbustr(‘ABCdef’,-3,2) de
  11. 数字函数
    trunc(1234.56) from dual 1234
    round(1234.56) from dual 1235
    select trunc(123.45,1)from dual 123.4
    trunc(123.45,-1) 120
    trunc(123.45,-3) 0
  12. 日期
    to_char(sysdate,’yyyy-mm-dd hh24:mi:ss’)(把时间改为字符串)
    to_date(‘1990-01-23’,’yyyy-mm-dd’)(把字符串转为时间)
  13. 子查询
    一般不在子查询中用order by
    多行子查询比较符:in(等于任意一个)\any(任意一个比较,大于最小)\all(大于最大)
  14. 多表查询
    笛卡尔积:
    select * from score s1,course c,student s2 where s1.sid=s2.sid, and s1.cid=c.cid;
    内连接:
    select * from score s1 inner join course c on s1.cid=c.cid inner join student s2 on s1.sid=s2.sid;
    左外连接(左表全部显示):
    select * from score s1 left outer join course c on s1.cid=c.cid left outer join student s2 on s1.sid=s2.sid;
    右外连接:rightrt outer join on
    全连接:full outer join on
  15. 分组查询:
    select (中间只能出现被by的字段和组函数(max(),min()等)) from
    group br 放在 where 后面

select dept_id,avg(salary) from s_emp group by dept_id having avg(salary)>(select avg(salary) from s_emp where dept_id = 21) ;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值