zoukankan      html  css  js  c++  java
  • rownum&&rowid

    伪列:不属于任何一张表,但是会被所有的表共享

    rownum:逻辑序列1 2 3 4....
    rowid:物理序列(18)真实的存放位置

    rownum:不同的SQL语句在执行时,rownum的值不一致
    在相同SQL语句在执行时,rounum的值不变


    查询工资最高的前三条员工信息
    select rownum,ename,sal from
    (select * from emp order by sal desc)
    where rownum<=3;

    top-n 前n个数据:
    select rownum,...from (select * from xxx order by ...) where rownum <= n;


    rownum/rowid:删除重复数据


    create table mystudent(
    stuno number,
    stuname varchar2(10),
    stuage number
    );

    insert into mystudent values(1,'zs',23) ;
    insert into mystudent values(1,'zs',23) ;

    insert into mystudent values(2,'ls',24) ;
    insert into mystudent values(2,'ls',24) ;

    insert into mystudent values(3,'ww',25) ;
    insert into mystudent values(3,'ww',25) ;

    insert into mystudent values(4,'zl',26) ;


    delete from mystudent where stuno in(
    select distinct stuno from mystudent);//不可用

    去重:distinct


    rowid:根据插入的顺序 依次递增


    rownum:逻辑伪列

    rowid:物理伪列,18位:
    前6位: 数据对象编号
    依次往后数3位:数据文件编号
    依次往后数6位:数据块编号
    依次往后数3:行号
    思路:
    根据编号分组(将重复的数据 放到一组) ,然后在每组中只保留一个

    保留:rowid最小的
    delete from mystudent where rowid not in (select min(rowid) from mystudent group by stuno );

  • 相关阅读:
    把字符串输入到表格里
    x 的 x 次方等于10,求 x
    java 中 二进制串与浮点数的相互转化
    堆栈 Objective-C NSString copy strong
    c一些学习过程中突然错过的细节
    视图控制器
    名词从句
    FastDFS
    Python
    http 提交表单数据
  • 原文地址:https://www.cnblogs.com/mayouyou/p/13199841.html
Copyright © 2011-2022 走看看