Retrieve Only First x Rows
From time to time you may have the need to grab the top X number of rows returned from a table. For instance “give me the 10 vendors we pay the most from the voucher table”.
This might seem impossible in something like query as there is no way to stop the output after 10 rows… unless you use the SQL below that will let you do just that:
What this will do is run the inner SQL statement (a view that acts like a table) that will grab vendor counts from the voucher table and order it by the count descending. Then the outer SQL statement will only show the first 10 rows returned.
If you needed a larger number simply increase the 10 to what ever count you need. This particular SQL can be slow since it is doing a full table scan of the voucher table.
The return from this table can also be joined to other tables for a report. (This example would need more fine-tuning to pull the single row desired from PS_VENDOR_ADDR, but for simplicity the correct SQL has not been added.)
Retrieve Only First x Rows的更多相关文章
- Hibernate--------八大类HQL查询集合
Hibernate的 八大类HQL查询集合 Hibernate的八大类HQL查询集合: 一:属性查询(SimplePropertyQuery) 1,单一属性查询 *返回结果集属性列表,元素类型和实 ...
- 【Android Api 翻译4】android api 完整翻译之Contacts Provider (学习安卓必知的api,中英文对照)
Contacts Provider 电话簿(注:联系人,联络人.通信录)提供者 ------------------------------- QUICKVIEW 快速概览 * Android's r ...
- Laravel Quickstart
Installation Via Laravel Installer First, download the Laravel installer using Composer. composer gl ...
- SQL Fetch size
JDBC performance tuning with optimal fetch size February 1, 2009 31 Comments Tuning performance usin ...
- Intel daal数据预处理
https://software.intel.com/en-us/daal-programming-guide-datasource-featureextraction-py # file: data ...
- Oracle Flashback Transaction Query with Oracle Flashback Version Query
Oracle Flashback Transaction Query with Oracle Flashback Version Query In this example, a database a ...
- DBCC CHECKDB 遭遇Operating system error 112(failed to retrieve text for this error. Reason: 15105) encountered
我们一个SQL Server服务器在执行YourSQLDBa的作业YourSQLDba_FullBackups_And_Maintenance时遇到了错误: Exec YourSQLDba.Maint ...
- CentOS系统yum源使用报错:Error: Cannot retrieve repository metadata (repomd.xml) for repository: rpmforge.
服务器上的yum突然不好使用,使用yum的时候报错如下:[root@bastion-IDC src]# yum list......Could not retrieve mirrorlist http ...
- Write on ……… failed: 112(failed to retrieve text for this error. Reason: 15105)
早上检查数据库的备份邮件时,发现一台Microsoft SQL Server 2008 R2 (SP2)数据库的Maintenance Report有错误 在SSMS里面执行Exec YourSQLD ...
随机推荐
- jhat中的OQL(对象查询语言)
http://blog.csdn.net/wanglha/article/details/40181767 jhat中的OQL(对象查询语言) 如果需要根据某些条件来过滤或查询堆的对象,这是可能的,可 ...
- Jmeter+Jenkins集成html报告显示问题
在J meter+Jenkins集成生成的html报告时,出现如下问题:无法正常显示表格,detail内容无法折叠和展开操作. 解决方法:执行下列脚本行 在Jenkins :系统管理--脚本命令行 S ...
- Thinkpad X240在Centos 7下使用ID 138a:0017或者vfs5011指纹识别
我的笔记本是ThinknPad X240,自带的指纹识别器,通过命令lsusb可以查看: [zz@zz ~]$ lsusb Bus 001 Device 002: ID 24ae:2003 Bus 0 ...
- 【转】深入理解DIP、IoC、DI以及IoC容器
原文链接:http://www.cnblogs.com/liuhaorain/p/3747470.html 前言 对于大部分小菜来说,当听到大牛们高谈DIP.IoC.DI以及IoC容器等名词时,有没有 ...
- [ActionScript 3.0] Away3D 天空盒(skybox)例子2
所谓skybox就是六个面即六张图能够无缝的拼成一个正方体的盒子. package { import away3d.cameras.Camera3D; import away3d.cameras.le ...
- grunt构建前端自动化的开发环境
废话不多说.直奔主题. 1.安装node. 别问为什么.如果你不知道,说了你还是不知道. 别问怎么安装,自己去百度. 2.安装grunt_CLI. 安装完node,并且安装成功了,后.下载grunt_ ...
- 把exe嵌入到自己的exe中。delphi xe3
下面是一个把exe程序嵌入到我们自己的exe中.开发环境 Delphi XE3 Version 17.0.4625.53395.OS环境WIN7 SP1,由于xe3版本的引用库发生变化.换成其他版本的 ...
- 【转】windows和linux间共享互传文件
原文:http://blog.guorunmin.cn/2015/09/16/windows%E5%92%8Clinux%E9%97%B4%E5%85%B1%E4%BA%AB%E4%BA%92%E4% ...
- JAXB注解【转】
http://blog.csdn.net/lw371496536/article/details/6942045 JAXB(Java API for XML Binding),提供了一个快速便捷的方式 ...
- 项目积累——JAVA知识积累
调用天气: <iframe src="http://www.thinkpage.cn/weather/weather.aspx?uid=&c=CHXX0008&l=zh ...