postgresql之distinct用法
1. 去重;关键字distinct去重功能 在其他数据库(oracle,mysql)是存在;当然postgresql也有这个功能
[postgres@sdserver40_210 ~]$ psql mydb lottu
psql (9.5.)
Type "help" for help. mydb=> select * from trade;
tradeno | accountid | fee | game_id
---------+------------+-----+---------
| yyb_100001 | |
| yyb_100002 | |
| yyb_100001 | |
| yyb_100003 | |
| yyb_100004 | |
| yyb_100002 | |
( rows) mydb=> select distinct accountid from trade;
accountid
------------
yyb_100001
yyb_100004
yyb_100002
yyb_100003
( rows) mydb=> select distinct accountid,game_id from trade;
accountid | game_id
------------+---------
yyb_100001 |
yyb_100003 |
yyb_100004 |
yyb_100002 |
( rows)
mydb=> select distinct on (accountid) accountid,fee from trade;
accountid | fee
------------+-----
yyb_100001 |
yyb_100002 |
yyb_100003 |
yyb_100004 |
( rows) mydb=> select distinct on (game_id) accountid,fee from trade;
accountid | fee
------------+-----
yyb_100001 |
( row) mydb=> select distinct on (game_id) accountid,fee from trade order by game_id, fee desc;
accountid | fee
------------+-----
yyb_100002 |
( row) --例如取每个帐号充值最大的一笔
mydb=> select distinct on (accountid) accountid,fee from trade order by accountid, fee desc;
accountid | fee
------------+-----
yyb_100001 |
yyb_100002 |
yyb_100003 |
yyb_100004 |
( rows)
postgresql之distinct用法的更多相关文章
- 转一个distinct用法,很有帮助
转一个distinct用法,很有帮助 (2011-12-01 15:18:11) 转载▼ 标签: 杂谈 分类: mysql复制 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提 ...
- mysql distinct 用法详解及优化
本事例实验用表task,结构如下 MySQL> desc task; +-------------+------------+------+-----+-------------------+- ...
- PostgreSQL>窗口函数的用法
PostgreSQL之窗口函数的用法 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9311281.html PostgreSQL的高级特性本准备三篇的(递归. ...
- distinct用法
distinct可以列出不重复的记录,对于单个字段来说distinct使用比较简单,但是对于多个字段来说,distinct使用起来会使人发狂.而且貌似也没有见到微软对distinct使用多字段的任何说 ...
- [Irving]SQL去重复-DISTINCT用法
在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值.关键词 distinct用于返回唯一不同的值. 表A: 示例1 select distinct nam ...
- PostgreSQL 的 distinct on 的理解
摘录自:http://www.cnblogs.com/gaojian/archive/2012/09/05/2671381.html 对于 select distinct on , 可以利用下面的例子 ...
- mysql distinct()用法
在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所 ...
- Pig distinct用法举例
dst = distinct data: DISTINCT只能对整个记录(整行)去重,不能在字段级别去重. 触发reduce阶段 data = load 'data'; distinct ...
- mysql中去重 distinct 用法
在使用MySQL时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count( ...
随机推荐
- set方法内存分析
// // main.m // 04-set方法的内存管理分析 // // Created by apple on 14-3-17. // // #import <Foundation/F ...
- Java IO之一读取文件
package com.lf.iopreoject; import java.io.BufferedReader; import java.io.File; import java.io.FileIn ...
- (转)在PHP语言中使用JSON
原文 : http://www.ruanyifeng.com/blog/2011/01/json_in_php.html --------------------------------------- ...
- Oracle Flashback Technologies (总)
Oracle Flashback Technologies Oracle 9i中增加了闪回查询技术,闪回查询为数据库提供了一种简单.强大.完全无干扰从人为错误中恢复的机制.通过闪回查询,用户可以查看过 ...
- Java基础之处理事件——实现低级事件监听器(Sketcher 2 implementing a low-level listener)
控制台程序. 定义事件监听器的类必须实现监听器接口.所有的事件监听器接口都扩展了java.util.EventListener接口.这个接口没有声明任何方法,仅仅用于表示监听器对象.使用EventLi ...
- PostgreSQL数据库中跨库访问解决方案
PostgreSQL跨库访问有3种方法:Schema,dblink,postgres_fdw. 方法A:在PG上建立不同SCHEMA,将数据和存储过程分别放到不同的schema上,经过权限管理后进行访 ...
- Leetcode: Number of Islands II && Summary of Union Find
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...
- [reprint]如何编写引导程序 Hello World
在存储介质(硬盘.软盘.光盘)中有一块特殊的区域,叫做引导区.在计算机启动后,BIOS会读取引导区内的代码到内存中去,然后将执行这些代码.引导区的位置和大小与计算机的平台有关,对于IBM-PC兼容机, ...
- for穷举
穷举:把所有可能的情况都走一遍,使用if条件筛选出来满足的条件的情况.(把所有的可能性都列举一边) 迭代:从初始情况按照规律不断求解中间情况,最终推导出结果.f foreach 专为数组定义的一种命 ...
- override 与 overdown 的区别
重写与重载的区别 1. 重载是方法的名称相同.参数或参数类型不同,进行多次重载以适应不同的需要 2. 重写是进行基类中函数的重写.为了适应需要.