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

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

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

    隨筆-124  評(píng)論-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 取消重復(fù)
    select count(distinct user_nameas num
    from user_info

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

    7 group by + cube  縱向小計(jì)
    -- group by + cube  縱向小計(jì)
    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(不能單獨(dú)使用,與單行比較符[=,>,<,>=,<=,<>]結(jié)合使用)
    --ALL和ANY(不能單獨(dú)使用,與單行比較符[=,>,<,>=,<=,<>]結(jié)合使用)
    /*
    ALL 必須要符合子查詢結(jié)果的所有值
    ANY 只要符合子查詢結(jié)果的任一個(gè)值即可
    */

    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 取兩個(gè)結(jié)果集的并集,自動(dòng)去掉重復(fù)行并以第一列的結(jié)果排序
    --
    (2)union all 取兩個(gè)結(jié)果集的并集,不去重復(fù)行也不進(jìn)行排序
    --
    (3)intersect 取兩個(gè)結(jié)果集的交集
    --
    (4)minus 取兩個(gè)結(jié)果集的差集
    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 刪除重復(fù)記錄
    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 閱讀(384) 評(píng)論(0)  編輯  收藏 所屬分類: oracle/mysql/sql
    主站蜘蛛池模板: 一个人免费观看在线视频www| 成年大片免费视频| 成人无遮挡毛片免费看| 亚洲女人被黑人巨大进入| 亚洲人成网址在线观看| 亚洲av无码成人影院一区| 永久免费不卡在线观看黄网站| 日韩精品福利片午夜免费观着| 亚洲毛片网址在线观看中文字幕 | 亚洲国产高清在线精品一区| 美女露100%胸无遮挡免费观看| 久久国产乱子免费精品| 国产成人免费ā片在线观看| 亚洲一区二区三区日本久久九| 爱爱帝国亚洲一区二区三区| 96免费精品视频在线观看| 哒哒哒免费视频观看在线www| 亚洲高清中文字幕综合网| 五月天婷婷免费视频| 在线观看免费高清视频| 久久久亚洲精品蜜桃臀| 2020天堂在线亚洲精品专区| 国产免费拔擦拔擦8X高清在线人 | 青娱乐免费视频在线观看| 亚洲精品无码专区在线在线播放| 亚洲熟妇无码八V在线播放| 一个人免费日韩不卡视频| 亚洲阿v天堂在线2017免费| 最新国产精品亚洲| 三年片在线观看免费大全电影 | 国产精品无码亚洲精品2021| 亚洲免费一级视频| 亚洲精品成人片在线播放 | 国产精品亚洲A∨天堂不卡 | 成人无码视频97免费| 国产免费人成在线视频| 亚洲天堂男人影院| 最近免费中文字幕mv在线电影| 亚洲一区二区三区乱码A| 亚洲国产精品嫩草影院| 国产a视频精品免费观看|