posts - 431,  comments - 344,  trackbacks - 0

          在DB2中, 使用FETCH FIRST子句限制返回行數:
              select * from emp fetch first 5 rows only
          使用RAND與ORDER BY和FETCH FIRST來獲取隨機條數
              select * from emp order by rand() fetch first 5 rows only

          在MySQL和PostgreSQL中, 使用LIMIT:
              select * from emp limit 5
          MySQL中獲取隨機行數:
               select * from emp order by rand() limit 5
          PostgreSQL中獲取隨機行數:
               select * from emp order by random() limit 5

          在Oracle中, 在WHERE子句中通過使用ROWNUM來限制行數:
              select * from emp where rownum <= 5
              
              select *
                      from (
                          select ename, job from emp order by dbms_random.value()
                      )
              where rownum <= 5
          在SQL Server中, 使用TOP來限制返回行數:
              select top 5 * from emp
              
              select top 5 ename, job from emp order by newid()

          posted on 2008-07-15 20:50 周銳 閱讀(635) 評論(0)  編輯  收藏 所屬分類: MySQLOracleSQL Server
          主站蜘蛛池模板: 金平| 天水市| 克什克腾旗| 定结县| 织金县| 大名县| 文登市| 雅江县| 湘西| 克东县| 铅山县| 安乡县| 武夷山市| 民权县| 信丰县| 潞城市| 紫云| 延长县| 牟定县| 镇平县| 泗阳县| 赤峰市| 余庆县| 桐乡市| 南江县| 周宁县| 曲水县| 辽阳市| 中江县| 临城县| 孟津县| 彭阳县| 虞城县| 远安县| 九龙城区| 靖江市| 婺源县| 平舆县| 泾源县| 娱乐| 平陆县|