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 );

  • 相关阅读:
    SQL 查询当前时间
    request,reponse对象中的方法
    如何在JSP中获得Cookie对象
    JSP的执行原理
    ModelState查看错误字段的信息
    sql privot 实现行转列
    设计模式
    mvc未登录跳转到登录界面
    log4net
    IoC, DI,Spring.net
  • 原文地址:https://www.cnblogs.com/mayouyou/p/13199841.html
Copyright © 2011-2022 走看看