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将一段逗号分割的字符串转换成一个数组
String 类:String 类代表字符串.Java 程序中的所有字符串字面值都作为此类的实例实现.字符串是常量,它们的值在创建之后不能更改.字符串缓冲区支持可变的字符串.因为 String 对象是 ...
- 新建的表如果还没有数据,用exp导的时候会忽略
源地址:http://www.07net01.com/2015/07/884873.html
- poj 1753 Flip Game
点击打开链接 Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25674 Accepted: 1109 ...
- HTTP 和 HTTPS 协议
HTTP协议是什么? 简单来说,就是一个基于应用层的通信规范:双方要进行通信,大家都要遵守一个规范,这个规范就是HTTP协议. HTTP协议能做什么? 很多人首先一定会想到:浏览网页.没错,浏览网页是 ...
- hdu 1255 覆盖的面积(线段树 面积 交) (待整理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 Description 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. In ...
- php读取目录及子目录下所有文件名的方法
本文实例讲述了php读取目录及子目录下所有文件名的方法,分享给大家供大家参考.具体实现方法如下: 一般来说php中读取目录下的文件名的方式确实不少,最简单的是scandir,具体代码如下: $dir= ...
- 命令行运行jmeter脚本
1.通过gui界面的jmeter创建一份脚本:2.打开cmd,切换到jmeter程序的Bin目录:3.执行jmeter.bat -n -t bookair_0613.jmx -l log_3.jtl: ...
- MXNet官网案例分析--Train MLP on MNIST
本文是MXNet的官网案例: Train MLP on MNIST. MXNet所有的模块如下图所示: 第一步: 准备数据 从下面程序可以看出,MXNet里面的数据是一个4维NDArray. impo ...
- Oracle 查看表空间剩余与创建空间语法
select a.tablespace_name,total,free,total-free used from ( select tablespace_name,sum(bytes)/1024/10 ...
- socket学习笔记——select与epoll函数的使用(linux)
select.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <u ...