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( ...
随机推荐
-
《Entity Framework 6 Recipes》中文翻译系列 (36) ------ 第六章 继承与建模高级应用之TPC继承映射
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 6-12 TPC继承映射建模 问题 你有两张或多张架构和数据类似的表,你想使用TP ...
-
poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
-
tcpdump使用技巧
tcpdump使用技巧 http://www.veryarm.com/1751.html
-
Qt setStyleSheet 添加背景色/背景图片(取消背景色,读取本地文件作为背景色)
容易搞定,mainWindow 是一个QWidget.// 设置背景色为蓝色mainWindow.setStyleSheet("background-color:blue;"); ...
-
常用的 css 样式 记录
1.font-style 属性指定文本的字体样式. 对应的值有: normal 默认值.浏览器显示一个标准的字体样式; italic 浏览器会显示一个斜体的字体样式; oblique 浏览器会显 ...
-
kubernetes1.14.0部署
2019/4/6/使用kubeadm安装部署kubernetes集群: 前提:1.各节点时间同步:2.各节点主机名称解析:dns OR hosts:3.各节点iptables及firewalld服务被 ...
-
tkinter widget
tkinter messagebox
-
2.2、CDH 搭建Hadoop在安装(安装Java Development Kit)
第2步:安装Java Development Kit 要安装Oracle JDK,您可以使用Cloudera Manager安装Cloudera提供的版本,也可以直接安装Oracle的其他版本. 继续 ...
-
在LaTeX中配置西夏文字体与环境
目录 1 配置字族 2 粗体.斜体设定 3 文本编辑器的字体设定(以Sublime Text为例) 4 附录:一些字体的下载源 警告:这篇文章的部分内容需要西夏文字体才能正常显示.若您需要安装,可参考 ...
-
剑指 Offer——连续子数组的最大和
1. 题目 2. 解答 初始化 sum=0,然后遍历数组进行累加.如果 sum 变为负数,也就说再继续累加的话贡献为负,我们需要更新 sum=0,重新开始累加. 初始化 max_sum 为数组的第一个 ...