zoukankan      html  css  js  c++  java
  • oracle中构造序列

    Oracle Row Generator Techniques

    http://www.club-oracle.com/forums/row-generation-method-in-sql-also-in-pl-sql-t129/

    http://www.orafaq.com/wiki/Oracle_Row_Generator_Techniques
    早期使用----- select rownum from all_objects where rownum <xxx

    现在可以使用-----select rownum from dual connect by rownum<xxx

    或者----select level from dual connect by level<xxx

    要实现当前年份的前五年至后十年的下拉列表,方式1

     1 SELECT DECODE(B.ROWN,
    2 1,
    3 COUNTS - 5,
    4 2,
    5 COUNTS - 4,
    6 3,
    7 COUNTS - 3,
    8 4,
    9 COUNTS - 2,
    10 5,
    11 COUNTS - 1,
    12 6,
    13 COUNTS,
    14 7,
    15 COUNTS + 1,
    16 8,
    17 COUNTS + 2,
    18 9,
    19 COUNTS + 3,
    20 10,
    21 COUNTS + 4,
    22 11,
    23 COUNTS + 5)
    24 FROM (SELECT TO_CHAR(SYSDATE, 'YYYY') AS COUNTS FROM DUAL) A,
    25 (SELECT ROWNUM ROWN FROM ALL_OBJECTS WHERE ROWNUM <= 11) B

    要实现当前年份的前五年至后十年的下拉列表,方式2

    1 SELECT TO_CHAR(SYSDATE, 'yyyy') - (5 - NUMS)
    2 FROM (SELECT ROWNUM NUMS FROM ALL_OBJECTS WHERE ROWNUM < 6)
    3 UNION ALL
    4 SELECT TO_CHAR(SYSDATE, 'yyyy') + NUMS
    5 FROM (SELECT ROWNUM NUMS FROM ALL_OBJECTS WHERE ROWNUM < 6)

    考试题:

    查询一个表中相同的名字的人的个数(使用名字进行分组,假如没有重名的,则它的count值为1.判断为1的时候,进行减1

    运算,当不为1的时候,不进行减法)

    1 SELECT SUM(COUNTS)
    2 FROM (SELECT CASE COUNT(*)
    3 WHEN 1 THEN
    4 COUNT(*) - 1
    5 ELSE
    6 COUNT(*)
    7 END COUNTS
    8 FROM A
    9 GROUP BY A.NAMES)

    查询每个月注册的用户的总数

    1 SELECT COUNT(*), BB.MM
    2 FROM (SELECT B.*, TO_CHAR(B.CREATE_TIME, 'MM') MM FROM B) BB
    3 GROUP BY BB.MM
    4 ORDER BY BB.MM

    查询在某一区间的数据

    1 SELECT *
    2 FROM (SELECT ROWNUM AS NUMS, A.*
    3 FROM (SELECT * FROM EMP E ORDER BY E.EMPNO) A) B
    4 WHERE B.NUMS > 7;








    I believe that we are who we choose to be. Nobody‘s going to come and save you, you‘ve got to save yourself. 我相信我们成为怎样的人是我们自己的选择。没有人会来拯救你,你必须要自己拯救自己。
  • 相关阅读:
    使用c#读取/解析二维码
    MVVM中的RelayCommand与AsyncCommand
    MVVM模式下的OpenFileDialog
    集成Source Monitor至VS中
    [转]异步command的实现
    使用Messenger实现MVVM的对话框弹出
    使用NPOI访问、控制Excel
    win11更新
    Codeforces Round #749 总结
    Codeforces Round #697 (Div. 3)
  • 原文地址:https://www.cnblogs.com/caroline/p/2283575.html
Copyright © 2011-2022 走看看