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 ...
随机推荐
- 创建指定日期java Date对象
import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import ...
- nginx 环境搭建(基于linux)
Nginx是一种服务器软件,故而其最主要.最基本的功能当然是可以与服务器硬件结合,让程序员可以将程序放在Nginx服务器上,将程序发布出去,让成千上万的网民可以浏览.除此之外,Nginx是一种高性能的 ...
- C++学习33 函数模板
在<C++函数重载>一节中,为了求三个数的最大值,我们通过函数重载定义了三个名字相同.参数列表不同的函数,如下所示: //求三个整数的最大值 int max(int a, int b, i ...
- [Java] 实现一个基于命令行的用户管理
实现基于一个命令行的用户管理,控制台操作 控制类 /* * 文 件 名: mvc.my.test.UserInterface.java * 版 权: XXX Technologies Co., Ltd ...
- [ActionScript 3.0] Away3D 天空盒(skybox)例子
/* SkyBox example in Away3d Demonstrates: How to use a CubeTexture to create a SkyBox object. How to ...
- [Flex] ButtonBar系列——labelFunction用户提供的函数,在每个项目上运行以确定其标签
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- 动手学servlet(一) 第一个servlet程序
1.文件>新建>动态WEB项目 "javaeedemo">在Java Resource的src下新建包“servletdemo”,包下新建一个类“MyServet ...
- 通过 adb命令发送广播
我们经常用到模块设备发送广播,此处记录一下: 首先进入adb 使用命令: adb shell 发送广播 例: am broadcast -a action.com.custom.broadcast.q ...
- maven搭建项目的时候,src/main/java无法建立的问题,提示信息The folder is already a source folder.(文件夹已经是源文件夹。)
原因:maven自己引的jdk包不对,需要重新引包 操作方式: 1.在项目上右击(或用快捷键ALT+ENTER),打开properties-->java builder path-->re ...
- 科普:什么是IPV4?什么是IPV6?
IPv4是Internet Protocol version 4(网际协议版本4)的英文简称,而中文简称为“网协版4”. 目前的全球因特网所采用的协议族是TCP/IP协议族.IP是TCP/IP协议族中 ...