select *
from emp fetch first 5 rows only
MySQL 和 PostgreSQL
在 MySQL 和 PostgreSQL 中,使用 LIMIT 来限制返回的行数。
select *from emp limit 5
Oracle
在 Oracle 中,要限制返回的行数,可以在 WHERE 子句中对 ROWNUM 进行限制。
select *from empwhere rownum <= 5
SQL Server
在 SQL Server 中,使用关键字 TOP 来限制返回的行数。
select top 5 *from emp
select ename, jobfrom emp
select ename,jobfrom emporder by rand() fetch first 5 rows only
MySQL
结合使用内置函数 RAND、LIMIT 和 ORDER BY。
select ename,jobfrom emporder by rand() limit 5
PostgreSQL
结合使用内置函数 RANDOM、LIMIT 和 ORDER BY。
检索记录 | 9
select ename,jobfrom emporder by random() limit 5
Oracle
结合使用(内置包 DBMS_RANDOM 中的)内置函数 VALUE、ORDER BY 子句和内置函数 ROWNUM。
select *from (select ename, jobfrom emporder by dbms_random.value())where rownum <= 5
SQL Server
结合使用内置函数 NEWID、TOP 和 ORDER BY 来返回随机的结果集。
select top 5 ename,jobfrom emp
## 标题 order by newid()
**
**
select coalesce(comm,0)from emp
select casewhen comm is not null then commelse 0endfrom emp
虽然可以使用 CASE 将 NULL 值转换为实际值,但使用 COALESCE 更容易且更简洁
上一篇:QT QThread 多线程操作