• 数据库中随机查询数据


    数据库的随机查询SQL 
     

    1. Oracle,随机查询20条

    select * from

    (
     select  *  from 表名
     order by dbms_random.value

    )
     where rownum <= 20;

    2.MS SQL Server,随机查询20条

    select top 20  * from  表名order by newid()

    3.My SQL:,随机查询20条

    select  *  from  表名 order by rand() limit 20

    随机查询指定人员的一条未读消息
     
    帮助消息表 S_MSG_HINT
    帮助消息ID SMH_ID NUMBER(20) PK
    帮助消息内容 SMH_TEXT VARCHAR2(200)
     
    人员帮助消息表 S_HINTPEOPLE
    人员ID SHP_UID VARCHAR2(20) PK
    当前帮助消息ID SMH_ID NUMBER(20)  PK FK
     
    如果为已读消息会在 人员帮助消息表里面生成记录
     
    select
        *
    from
        (select
            smh.*,
            nvl2( shp.smh_id,1,0) as status --0:未读 1:已读
        from
            s_msg_hint smh
                    left join s_hintpeople shp 
                        on smh.smh_id = shp.smh_id 
                        and shp.shp_uid = 'p_chencc'
        order by
            dbms_random.value  --随机数值排序
        )
    where
        status = 0 and --未读消息
        rownum <= 1  --取一条

  • 相关阅读:
    30个在线学习设计与开发的站点
    马云:你的一生到底该往哪个方向走?
    那些争议最大的编程观点
    Python 标识符
    Python 环境搭建
    Python 简介
    PyCharm 使用技巧
    Shell脚本———— /dev/null 2>&1详解
    linux 创建连接命令 ln -s 软链接
    scp命令详解
  • 原文地址:https://www.cnblogs.com/gisblogs/p/4126555.html
Copyright © 2020-2023  润新知