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 ...
随机推荐
- ruby api 2.1新增改变
-> 这个符号可以替换lambda%i 生成符号数组 %i(foor bar baz) #[:foo,:bar:baz]def 定义方法 eg: def foo(x: 1); puts; end ...
- [ActionScript 3.0] 跨域策略文件crossdomain.xml配置详解
1.简介 flash在跨域时唯一的限制策略就是crossdomain.xml文件,该文件限制了flash是否可以跨域读写数据以及允许从什么地方跨域读写数据. 位于www.a.com域中的SWF文件要访 ...
- Go 支持Protocol Buffers的配置
安装 protoc (The protocol compiler)是由C++写的,支持的 C++.Java.Python.Objective-C.C#.JavaNano.JavaScript.Ruby ...
- [SQL]开启事物,当两条插入语句有出现错误的时候,没有错误的就插入到表中,错误的语句不影响到正确的插入语句
begin transaction mustt insert into student values(,'kkk','j大洒扫','j','djhdjh') insert into student v ...
- ASP.Net软件工程师基础(三)
1.多态 答: (1)虚方法 public class Child : Person { public void Speach() { base.Speach(); } public virtual ...
- phpmyadmin #2003 无法登录 MySQL服务器的解决方法
本文章向大家介绍phpmyadmin #2003 无法登录 MySQL服务器的解决方法,需要的码农可以参考一下. 通过phpmyadmin连接mysql数据库时提示:"2003 无法登录 M ...
- C# 学习的随笔【随时更新】
1.结束自己 Application.Exit(); //这个东西有重载函数
- 交易Txt文件导出
private void writeFYFileToTxt(List list, HttpServletRequest request, String drxh, FileOutputStream f ...
- 洗清UI自动化鸡肋说的不白之冤
人类文明发展的一个重要标识是工具的诞生,当人类开始制作工具来提高生产力时,就逐渐拉开了与其他生物的距离.曾在2013年,<Google如何测试软件>中提到的分层自动化金字塔,轰动业界.而在 ...
- 手写堆_C++
一般主程序中拿堆顶元素 x=h[]; h[]=h[top--]; down(); 在堆尾加入元素 h[++top]=x; up(top); 上浮下沉操作 inline void up(int x) { ...