distinct

MySQL学习日记-随笔PART2

女生的网名这么多〃 提交于 2020-01-22 12:34:44
1、关于查询结果集的去重? mysql> select distinct job from emp; // distinct关键字去除重复记录。 ±----------+ | job | ±----------+ | CLERK | | SALESMAN | | MANAGER | | ANALYST | | PRESIDENT | ±----------+ mysql> select ename,distinct job from emp; 以上的sql语句是错误的。 记住:distinct只能出现在所有字段的最前面。 mysql> select distinct deptno,job from emp; ±-------±----------+ | deptno | job | ±-------±----------+ | 20 | CLERK | | 30 | SALESMAN | | 20 | MANAGER | | 30 | MANAGER | | 10 | MANAGER | | 20 | ANALYST | | 10 | PRESIDENT | | 30 | CLERK | | 10 | CLERK | ±-------±----------+ 案例:统计岗位的数量? select count(distinct job) from emp; ±------------

[spark]RewriteDistinctAggregates

女生的网名这么多〃 提交于 2020-01-22 05:08:55
如果 Aggregate 操作中同时包含 Distinct 与非 Distinct 操作,优化器可以将该操作改写成两个不包含 Distinct 的 Aggregate 假设 schema 如下 create table animal ( gkey varchar ( 128 ) , cat varchar ( 128 ) , dog varchar ( 128 ) , price double ) ; animal 表中的数据如下 gkey cat dog price a ca1 cb1 10 a ca1 cb2 5 b ca1 cb1 13 测试语句如下 SELECT gkey , SUM ( price ) , COUNT ( DISTINCT cat ) , COUNT ( DISTINCT dog ) FROM animal GROUP BY gkey 该测试语句拥有3个 aggregate ,其中两个包含 distinct ,优化策略如下 首先将 animal 表格的每行扩展成 3 行,并添加新的一列 grid ,类型为整形,记新的表为 animal2 gkey cat dog price grid $gkey null null $price 0 $gkey $cat null null 1 $gkey null $dog null 2 表 animal2 数据如下

【数据库】相关代码集

ε祈祈猫儿з 提交于 2020-01-21 15:04:57
1 Create Table student 2 ( 3 Sno char (9) Primary key , 4 Sname char (20) Unique , 5 Ssex char (2) , 6 Sage smallint , 7 Sdept char(20) 8 9 ); 10 11 Create Table Course 12 ( 13 Cno char (4) Primary key , 14 Cname char (40) not Null , 15 Cpno char (4) , 16 Ccredit smallint 17 foreign key (Cpno) References Course(Cno) 18 ); 19 20 Create Table SC 21 ( 22 Sno char (9) , 23 Cno char (4) , 24 Grade smallint 25 26 Primary key ( Sno , Cno ) , 27 Foreign key ( Sno ) References Student (Sno), 28 Foreign key ( Cno ) References Course (Cno) 29 30 ); 31 32 Insert Into student(Sno,Sname,Ssex,Sage,Sdept) 33

MySQL 中去重 distinct 用法

和自甴很熟 提交于 2020-01-21 14:55:39
在使用 MySQL 时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count(distinct id)),其原因是distinct只能返回他的目标字段,而无法返回其他字段,例如有如下表user: 用distinct来返回不重复的用户名:select distinct name from user;,结果为: 这样只把不重复的用户名查询出来了,但是用户的id,并没有被查询出来:select distinct name,id from user;,这样的结果为: distinct name,id 这样的mysql 会认为要过滤掉name和id两个字段都重复的记录,如果sql这样写:select id,distinct name from user,这样mysql会报错,因为distinct必须放在要查询字段的开头。 所以一般distinct用来查询不重复记录的条数。 如果要查询不重复的记录,有时候可以用group by : select id,name from user group by name; 来源: https://www.cnblogs.com/zhuyongzhe/p/7693797.html

Hive分析窗口函数

谁说我不能喝 提交于 2020-01-19 15:31:17
Hive中提供了越来越多的分析函数,用于完成负责的统计分析。 今天简单整理一下,以务以后自己快速查询,也给看到的朋友作个参考。 分析函数主要用于实现分组内所有和连续累积的统计。 一. AVG,MIN,MAX,和SUM 如果不指定ROWS BETWEEN,默认为从起点到当前行; 如果不指定ORDER BY,则将分组内所有值累加; 关键是理解ROWS BETWEEN含义,也叫做WINDOW子句: PRECEDING:往前 FOLLOWING:往后 CURRENT ROW:当前行 UNBOUNDED:起点,UNBOUNDED PRECEDING 表示从前面的起点, UNBOUNDED FOLLOWING:表示到后面的终点 二. NTILE,ROW_NUMBER,RANK,DENSE_RANK 1) NTILE NTILE(n),用于将分组数据按照顺序切分成n片,返回当前切片值 NTILE不支持ROWS BETWEEN,比如 NTILE(2) OVER(PARTITION BY cookieid ORDER BY createtime ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) 如果切片不均匀,默认增加第一个切片的分布 2)ROW_NUMBER ROW_NUMBER() –从1开始,按照顺序,生成分组内记录的序列,比如,按照pv降序排列

mysql中去重 distinct 用法

末鹿安然 提交于 2020-01-18 19:28:10
在使用 MySQL 时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count(distinct id)),其原因是distinct只能返回他的目标字段,而无法返回其他字段,例如有如下表user: 用distinct来返回不重复的用户名:select distinct name from user;,结果为: 这样只把不重复的用户名查询出来了,但是用户的id,并没有被查询出来:select distinct name,id from user;,这样的结果为: distinct name,id 这样的mysql 会认为要过滤掉name和id两个字段都重复的记录,如果sql这样写:select id,distinct name from user,这样mysql会报错,因为distinct必须放在要查询字段的开头。 所以一般distinct用来查询不重复记录的条数。 如果要查询不重复的记录,有时候可以用group by : select id,name from user group by name; 来源: https://www.cnblogs.com/shiluoliming/p/6604407.html

Issue with android spinners - Loading distinct values in spinners

自闭症网瘾萝莉.ら 提交于 2020-01-17 08:12:11
问题 I'm using two Spinners to show the items I'm getting from the json response. I have 2 problems right now. When u check my logcat u can see there are items repeating (Right side list, u can see so many pan). I want to have 1 item only once in my Spinner. I want to use something similar to distinct we use in sql databases. My second problem is, Select pan in the 1 spinner then 2nd spinner should contain items related to pan. (select pan in 1st spinner and 2nd should display only Pan large, pan

Issue with android spinners - Loading distinct values in spinners

一笑奈何 提交于 2020-01-17 08:11:55
问题 I'm using two Spinners to show the items I'm getting from the json response. I have 2 problems right now. When u check my logcat u can see there are items repeating (Right side list, u can see so many pan). I want to have 1 item only once in my Spinner. I want to use something similar to distinct we use in sql databases. My second problem is, Select pan in the 1 spinner then 2nd spinner should contain items related to pan. (select pan in 1st spinner and 2nd should display only Pan large, pan

How to do sorting and select distinct in mogodb php query

泄露秘密 提交于 2020-01-17 03:53:08
问题 i have a mongo php query with aggregate frame work, now i want to add sorting and select distinct criteria to that query, please not that my query is working perfectly without these two criterias, take a look $result = $collection->aggregate(array( array( '$match' => array( 'Details.Model' =>"AUDI", 'Details.Color' => "RED", "Category" =>"Car" ) ), array( '$unwind' => '$Details' ), array( '$match' => array( 'Details.Model' =>"AUDI", 'Details.Color' => "RED", "Category" =>"Car" ) ), array( '

mysql distinct关键字(hive待确认)

大憨熊 提交于 2020-01-16 16:12:49
select a,b from tab ; 会按照 a,b两个字段进行去重。 MySQL DISTINCT with multiple columns You can use the DISTINCT clause with more than one column. In this case, MySQL uses the combination of values in these columns to determine the uniqueness of the row in the result set.    参考: https://www.mysqltutorial.org/mysql-distinct.aspx hive去重规则同上mysql: 参考; https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Select#LanguageManualSelect-ALLandDISTINCTClauses 来源: https://www.cnblogs.com/leodaxin/p/12201501.html