`
ytuwlg
  • 浏览: 92756 次
  • 性别: Icon_minigender_1
  • 来自: 威海
社区版块
存档分类
最新评论

Returning TOP N Records

    博客分类:
  • DB
阅读更多

 

Returning TOP N Records

Returning only the first N records in a SQL query differs quite a bit between database platforms.

 Here's some samples:

Microsoft SQL Server

SELECT TOP 10 column FROM table

PostgreSQL and MySQL

SELECT column FROM table
LIMIT 10

Oracle

SELECT column FROM table
WHERE ROWNUM <= 10

Sybase

SET rowcount 10
SELECT column FROM table

Firebird

SELECT FIRST 10 column 
FROM table

Due to these differences if you want to keep your code database independent you should use the maxrows attribute in the cfquery tag in ColdFusion. The tradeoffs to database independance is performance, I would expect maxrows to be slower than specifying the rows in the SQL.

<cfquery datasource="#ds#" maxrows="10">
SELECT column FROM table
</cfquery>

PostgreSQL and MySQL have a cool feature that will let you return an arbitrary range of rows (eg return rows 10-20). This is very handy for displaying pages of records:

SELECT column FROM table
LIMIT 10 OFFSET 20

The above query will return rows 20-30

 

 

 

分享到:
评论

相关推荐

    如何在Spring Boot中使用@AfterReturning注解

    1. **明确横切关注点**:在使用@AfterReturning 之前,确保你已经识别出了需要在目标方法执行后处理的横切关注点,如日志记录、性能监控或事务管理。 2. **合理定义切入点**:使用切入点表达式精确地定义哪些方法...

    findbugs:may expose internal representation by returning

    《深入理解FindBugs:可能通过返回暴露内部表示——“NULL”问题分析》 在软件开发过程中,确保代码的质量和安全至关重要。FindBugs作为一款静态代码分析工具,能够帮助开发者在程序运行前发现潜在的问题。...

    Python库 | django_pg_returning-1.0.0-py2.py3-none-any.whl

    python库。 资源全名:django_pg_returning-1.0.0-py2.py3-none-any.whl

    oracle RETURNING 子句使用方法

    Oracle的RETURNING子句是数据库操作中的一个强大特性,它允许在执行INSERT、UPDATE或DELETE语句时直接获取处理的数据结果。这在处理事务时非常有用,尤其是当你需要基于新插入或更新的数据进行进一步操作时。 1. **...

    Spring AOP定义AfterReturning增加实例分析

    Spring AOP 定义 AfterReturning 增加实例分析 Spring AOP (面向方面编程) 是 Spring 框架中的一种编程范式,旨在将切面编程融入到应用程序中。AfterReturning 是 Spring AOP 中的一种Advice (通知),它在目标方法...

    attr_copy.rar_The Returning

    "attr_copy.rar_The_Returning"这个标题暗示我们关注的是一个与复制文件属性相关的程序或函数,可能是一个C语言编写的源代码文件,即"attr_copy.c"。这个程序的功能是复制一个属性列表,并返回所占用的字节数。 `...

    TipTop函數大全.doc

    例如,`CALL cl_choice("请选择操作:") RETURNING g_choice`让用户选择并保存结果到g_choice。 13. **cl_open_url**: 打开URL链接的函数,通常用于在应用程序内打开网页。传入URL地址即可。例如,`CALL cl_open_...

    解决FLUSH、CMPLT、BKGND资源占用过高的问题

    top - 15:16:35 up 2 days, 20:45, 2 users, load average: 7.26, 7.17, 7.16 Tasks: 580 total, 2 running, 578 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.7%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%...

    《Pro Oracle SQL》CHAPTER 9 The Model Clause -- 9.4Returning Updated Rows

    9.4小节“Returning Updated Rows”讨论了在执行Model操作后如何获取更新后的行。在执行涉及Model子句的DML操作时,我们可能需要查看或验证哪些行被修改了,或者新状态是什么。通常,SQL更新操作不会返回更新的行,...

    An Eco-tour of returning to nature.zip

    "An Eco-tour of returning to nature.zip"这个压缩包文件为我们提供了一份关于生态旅游的详细资料,引领我们踏入一场回归自然的探索之旅。 首先,生态旅游(Eco-tourism)是一种尊重环境、保护生物多样性和促进...

    Tiptop GP 共用程式查询手册V1.1.doc

    - **用法**:`CALL cl_choice(l_msg) RETURNING g_choice`。此函数可以用于收集用户的选择信息,增强程序的交互性。 **13. cl_open_url** - **程序名稱**:cl_client_app.4gl - **用途**:通过浏览器打开指定网址。...

    TipTop 函數大全(百分之百完全收錄)

    CALL cl_choice(l_msg) RETURNING g_choice ``` #### 十三、`cl_open_url`函数 - **函数名**:`cl_open_url` - **程序名**:`cl_client_app.4gl` - **用途**:通过浏览器打开指定的URL。 - **传入参数**:`ps_...

    top.gg-core:top.gg API

    安装$ npm i top.gg-core定const top = require ( 'top.gg-core' ) ;... //post only server count | returning: booleantopgg . post ( { servers : client . guilds . cache . size , shard : { id : client . Shard

    TIPTOP内置函数

    用法示例:CALL cl_choice(l_msg) RETURNING g_choice。 最后,cl_open_url 函数用于打开指定的 URL。该函数需要一个输入参数,为 URL 字符串。没有返回值。 TIPTOP 内置函数提供了多种便捷的开发函数,涵盖了多个...

    returning-DOM-elements-javascript-源码.rar

    标题 "returning-DOM-elements-javascript-源码.rar" 暗示了这是一个关于使用JavaScript操作和检索DOM元素的源代码集合。DOM(Document Object Model)是HTML和XML文档的结构化表示,允许通过编程方式访问和修改文档...

    The specified CGI application misbehaved by not returning a complete set of HTTP headers

    是错误报告: The specified CGI application misbehaved by not returning a complete set of HTTP headers 意思是:(http协议的CGI模式运行不正确) 因为perl脚本的第一句中不支持 -wT 参数,将所有的 -wT 替换成...

Global site tag (gtag.js) - Google Analytics