posts - 431,  comments - 344,  trackbacks - 0

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

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

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

          posted on 2008-07-15 20:50 周銳 閱讀(635) 評(píng)論(0)  編輯  收藏 所屬分類: MySQLOracleSQL Server
          主站蜘蛛池模板: 石台县| 南溪县| 湖北省| 霞浦县| 镇安县| 湘潭市| 沧州市| 临颍县| 噶尔县| 陈巴尔虎旗| 孝义市| 大埔县| 贵德县| 杂多县| 六盘水市| 同仁县| 湄潭县| 清新县| 潜江市| 获嘉县| 大丰市| 奉新县| 六安市| 酉阳| 潼关县| 龙口市| 常熟市| 大理市| 寿宁县| 师宗县| 大名县| 鲁山县| 宜兰市| 永泰县| 长沙县| 金沙县| 德格县| 喀什市| 秦皇岛市| 松阳县| 滨州市|