• oracle之sql试题


    方法一:使用函数的方式

    select   count(*) Total,

    sum(decode(to_char(hiredate,'yyyy'),'1980',1,0))   ''1980'',

    sum(decode(to_char(hiredate,'yyyy'),'1982',1,0))   ''1982'',

     sum(decode(to_char(hiredate,'yyyy'),'1981',1,0))   ''1981'',

     sum(decode(to_char(hiredate,'yyyy'),'1987',1,0))   ''1987'',

    from   emp;

    DECODE的语法:

    DECODE(value,if1,then1,if2,then2,if3,then3,...,else),表示如果value 等于if1时,DECODE函数的结果返回then1,...,如果不等于任何一个if值,则返回else

    oracle 中to_char函数的用法

    一、日期格式转换

      to_char(date,'格式');

    二、数字格式转换

    to_char(number,'格式');

    三、金钱格式转换

    to_char(salary,'$99,99');

    方法二:使用子查询的方式

    select

    (select count(* ) from emp) Totall,

    (select count(* ) from emp where to_char(hiredate,'yyyy')='1980')  "1980",

    (select count(* ) from emp where to_char(hiredate,'yyyy')='1981')  "1981",

    (select count(* ) from emp where to_char(hiredate,'yyyy')='1982')  "1982",

    (select count(* ) from emp where to_char(hiredate,'yyyy')='1987')  "1987",

    from  dual

    dual 表

    DUAL是Oracle与数据字典一起自动创建的一个表。它只有一列:DUMMY,其数据类型为:VARCHAR2(1)。DUAL中只有一行数据:'X'。DUAL属于SYS模式,但所有用户都可以使用DUAL名称访问它。用SELECT计算常量表达式、伪列等值时常用该表,因为它只返回一行数据,而使用其它表时可能返回多个数据行。

    dual是一个oracle内部表,不论我们做什么操作(不要删除记录)它都只有一条记录,上面插入了一条之后,他仍然只有1条记录,所以很多取系统时间,计算,等只要选择一条记录,而且记录内容与表内容无关的操作,我们都喜欢使用这个表。虚表(dual)是oracle提供的最小的工作表,它仅包含一行一列。对于虚表(dual)来说,其中的列往往是不相关的或无关紧要的。

  • 相关阅读:
    golang-uuid
    golang-random随机数
    git status检测不到文件变化
    vimium
    go1.11新特性,mark一下
    HTML网页滚动加载--mark一下
    docker-清理none镜像等操作
    golang websocket
    postman 快捷方式--启动图标
    tmux基本操作
  • 原文地址:https://www.cnblogs.com/libaowen609/p/12819697.html
Copyright © 2020-2023  润新知