<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-124  評論-49  文章-56  trackbacks-0
    1

    table:citys
    city       ran

    廣州     A
    廣州     B
    廣州     C
    廣州     D

    city        ran

    廣州     A,B,C,D

    請問oracle  的sql語句要怎么寫?

    select city,wmsys.wm_concat(ran)
    from citys
    group by city


    2 備忘

    insert into emp (id,name,sex,tim) --dual
    values(id_seq.nextval,'junly',default,to_date('2010-5-11 11:25:00','yyyy-mm-dd hh24:mi:ss'))


    3 直接裝載

    --直接裝載方式
    insert /*+append*/ into emp (field1,field2,field3)
    select f1,f2,f3 from tep
    where f4=20;


    4 更新

    --更新
    update emp set (field1,field2,field3)=(
    select f1,f2,f3 from tep where f4=20)
    where field4=100;

    5 取消重復
    select count(distinct user_nameas num
    from user_info

    6 group by + rollup 橫向小計
    -- group by + rollup 橫向小計
    select num1,sum(num2),sum(num3) from tmp_tb
    group by rollup (num1)

    7 group by + cube  縱向小計
    -- group by + cube  縱向小計
    select num1,sum(num2),sum(num3) from tmp_tb
    group by cube(num1)

    8 自連接
    -- 自連接
    /* user_info
    id    name    pid
    -------------------
    7888  king    
    7889  blank   7888
    7900  jones   7888
    */

    select manager.name from user_info manager,user_info worker
    where manager.id=worker.pid
    and worker.name='jones';
    ----------
    king

    9 ALL和ANY(不能單獨使用,與單行比較符[=,>,<,>=,<=,<>]結合使用)
    --ALL和ANY(不能單獨使用,與單行比較符[=,>,<,>=,<=,<>]結合使用)
    /*
    ALL 必須要符合子查詢結果的所有值
    ANY 只要符合子查詢結果的任一個值即可
    */

    select user_name,money from user_info where money >all(
    select money form user_game where id=10);
    select user_name,money from user_info where money >any(
    select money form user_game where id>10);

    10 合并查詢
    --(1)union 取兩個結果集的并集,自動去掉重復行并以第一列的結果排序
    --
    (2)union all 取兩個結果集的并集,不去重復行也不進行排序
    --
    (3)intersect 取兩個結果集的交集
    --
    (4)minus 取兩個結果集的差集
    select uname,sal from emp where sal>200
    union 
    select uname,sal from emp where job='aaa'

    11 case條件分支
    select name,case when money>3000 then 3
    when money>2000 then 2 when money>1000 then 1 end
    from user_info where user_id=10000;

    12 with子名重用子查詢
    --with子名重用子查詢
    with summary as (
    select name,sum(moneyas total from user_info
    group by name
    )
    select name,total from summary 
    where total>3000;

    13 connect by (感謝廣州Nicholas兄)
    select sysdate - rownum rn from dual connect by rownum<100
    --
    select to_number(to_char(rn,'yyyymmdd'))rn from(select sysdate - rownum rn 
    from dual connect by rownum<(
    select floor(sysdate-regist_time)from sales_info where user_id=15587657))
    --月份
    select to_number(to_char(rn,'yyyymm'))rn from(
    select add_months(sysdate,-rownum) rn 
    from dual connect by rownum<(
    select floor(months_between(sysdate,regist_time)) from sales_info where user_id=15587657))

    14 批理修改
    merge into sales_info s 
    using tb_rd_user_info u
    on (s.user_id=u.user_id)
    when matched then
    update
    set s.user_name=u.user_name;
    commit;

    15 刪除重復記錄
    delete from user where rowid in (
    select max(rowid) from user group by userName having count(userName)>1)
    posted on 2010-07-28 09:46 junly 閱讀(383) 評論(0)  編輯  收藏 所屬分類: oracle/mysql/sql
    主站蜘蛛池模板: 亚洲男人天堂2022| 永久免费AV无码网站在线观看| 亚洲欧美日韩综合俺去了| 亚洲热线99精品视频| 国产高清在线免费| 2021国产精品成人免费视频| 永久免费av无码网站yy| 一级特黄色毛片免费看| 亚洲AV女人18毛片水真多| 亚洲成人一级电影| 亚洲国产精品自在线一区二区| 亚洲午夜国产精品无码老牛影视| 国产免费观看a大片的网站| 最近最新中文字幕完整版免费高清 | 亚洲熟妇AV乱码在线观看| 亚洲午夜在线电影| 亚洲妇熟XXXX妇色黄 | eeuss免费影院| 香港经典a毛片免费观看看| 亚洲国产成人无码AV在线| 亚洲免费网站在线观看| 亚洲视频在线观看网站| 亚洲av永久无码精品古装片| 亚洲精品成人片在线观看精品字幕| 亚洲欧洲国产成人综合在线观看| 亚洲成a人片在线播放| 婷婷亚洲天堂影院| 亚洲av无码不卡私人影院| 四虎影视永久免费观看地址| 免费h黄肉动漫在线观看| 国产hs免费高清在线观看| 国产a级特黄的片子视频免费| 国产jizzjizz免费看jizz| 免费成人午夜视频| 亚洲国产精品毛片av不卡在线| 免费又黄又爽的视频| 精品亚洲成α人无码成α在线观看 | 亚洲网站视频在线观看| 亚洲精品国产手机| 亚洲乱码一二三四区乱码| 狠狠色伊人亚洲综合网站色|