distinct

JSONArray转多行JSON

笑着哭i 提交于 2020-03-06 00:10:59
先通过explode把原数据变成n行数据,然后再用get_json_object去解析 select ss.json_col from ( select split(regexp_replace(regexp_extract('需要解析的jsonArray', '^\\[(.+)\\]$',1) ,'\\}\\,\\{', '\\}\\|\\|\\{'), '\\|\\|') as json_str from json_array_table ) pp lateral view explode(pp.json_str) ss as json_col; 实例: select ss.json_col from ( select split(regexp_replace(regexp_extract('[{"time":1582487998465,"_track_id":1358410713,"event":"joyLinkClick","_flush_time":1582488009148,"distinct_id":"6342133","properties":{"$os_version":"12.4.5","$device_id":"FCF68CFD-1F1A-4C2C-BA67-AD556C4EB125","app_name":"查悦社保","$carrier":"中国移动","

Get all column valus of a datatable based on only one distinct column [duplicate]

柔情痞子 提交于 2020-03-05 05:38:05
问题 This question already has answers here : How to select distinct rows in a datatable and store into an array (18 answers) Closed 5 years ago . I have a table with 10 columns and I want to get all values of each row but only of distinct IDs. I have this so far: DataTable Distinct = view.ToTable(true, "ID"); But this creates a DataTable that only contains the ID column. I want a DataTable with distinct ID's but containing all column values(there can be duplicates for the other columns.) Is there

Oracle关于left join on…and 及 left join on...whe...

ぃ、小莉子 提交于 2020-03-02 11:23:44
关于left join...on...and...以及left join...on...where的区别,网上很多的说法是对于left join...on...and...,and所限定的条件只对关联字段起作用,比如select a.* from tmp_table_a a left join tmp_table_b b on a.col1=b.col1 and b.col2=xx,很多人认为条件b.col2=xx是不起作用的。 对于这种说法,我个人是不认同的,至少来讲,这是一种不负责任的说法。以下是我的一些测试例子,从这里大家就可以理解这两个用法的区别。 select count(*) from tb_bo_valusr_new where month=201010 and brand=3;--141858 select count(*) from tb_bo_valusr_new where month=201010;---2281189 select count(distinct usr_nbr) from tb_bo_valusr_new where brand=3;--152110 select count(distinct usr_nbr) from tb_bo_valusr_new where month=201010;--2281189 select count(*

mysql数据库语法学习----4

有些话、适合烂在心里 提交于 2020-02-12 18:47:14
#isnull()函数 select ISNULL(a.commission_pct),commission_pct from employees a; --判断结果时候为空,为空的话就显示1,类似于true,不为空的话就显示0,类似于false #这样写导致查询出来的结果都是不规则的,所以会报错 select distinct department_id,distinct salary from employees; #这样写是对的,但是department_id会显示重复的数据 select distinct department_id, salary from employees; 来源: https://www.cnblogs.com/dongyaotou/p/12300007.html

4.2.7. Aggregate Expressions

浪子不回头ぞ 提交于 2020-02-12 12:28:54
4.2.7. Aggregate Expressions 4.2.7.聚合表达式 An aggregate expression represents the application of an aggregate function across the rows selected by a query. An aggregate function reduces multiple inputs to a single output value, such as the sum or average of the inputs. The syntax of an aggregate expression is one of the following: 聚合表达式表示在查询选择的行上应用聚合函数。 聚合函数将多个输入缩减为单个输出值,例如输入的总和或平均值。 聚合表达式的语法: aggregate_name (expression [ , ... ] [ order_by_clause ] ) [ FILTER ( WHERE filter_clause ) ] aggregate_name (ALL expression [ , ... ] [ order_by_clause ] ) [ FILTER ( WHERE filter_clause ) ] aggregate

Django的ORM操作-FQ-事物

ぃ、小莉子 提交于 2020-02-10 06:13:06
1,必知必会13条 <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 <3> get(**kwargs): 返回与所给筛选条件相匹配的对象,返回结果有且只有一个,如果符合筛选条件的对象超过一个或者没有都会抛出错误。 <4> exclude(**kwargs): 它包含了与所给筛选条件不匹配的对象 <5> values(*field): 返回一个ValueQuerySet——一个特殊的QuerySet,运行后得到的并不是一系列model的实例化对象,而是一个可迭代的字典序列 <6> values_list(*field): 它与values()非常相似,它返回的是一个元组序列,values返回的是一个字典序列 <7> order_by(*field): 对查询结果排序 <8> reverse(): 对查询结果反向排序,请注意reverse()通常只能在具有已定义顺序的QuerySet上调用(在model类的Meta中指定ordering或调用order_by()方法)。 <9> distinct(): 从返回结果中剔除重复纪录(如果你查询跨越多个表,可能在计算QuerySet时得到重复的结果。此时可以使用distinct(),注意只有在PostgreSQL中支持按字段去重。) <10> count():

MySQL对查询结果去重

我的未来我决定 提交于 2020-02-08 17:26:51
用 distinct 关键字去除重复记录,比如查询EMP表中JOB的种类: MariaDB [powernode]> select distinct JOB from EMP; 注意://下面这句sql语句是 错误 的,distinct只能出现在所有字段的最前面 MariaDB [powernode]> select ENAME,distinct JOB from EMP; 查询DEPTNO和JOB两栏都不重复的数据: MariaDB [powernode]> select distinct DEPTNO,JOB from EMP; 常见的案例:查询岗位的数量: MariaDB [powernode]> select count(distinct JOB) from EMP; 来源: CSDN 作者: 别断 链接: https://blog.csdn.net/Until_U/article/details/104222604

Linq 使用Distinct去重复项

南笙酒味 提交于 2020-02-07 21:50:44
Class DimEqualityComparer Inherits EqualityComparer(Of Dimension) Public Overrides Function Equals(ByVal d1 As Dimension, ByVal d2 As Dimension) As Boolean If d1 Is Nothing AndAlso d2 Is Nothing Then Return True ElseIf d1 Is Nothing OrElse d2 Is Nothing Then Return False ElseIf d1.DimensionText = d2.DimensionText Then Return True Else Return False End If End Function Public Overrides Function GetHashCode(ByVal d As Dimension) As Integer Return d.DimensionText.GetHashCode() End Function End Class Public Class ss_Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System

c# 扩展方法奇思妙用基础篇八:Distinct 扩展

天涯浪子 提交于 2020-02-07 01:05:42
刚看了篇文章 《 Linq的Distinct太不给力了 》,文中给出了一个解决办法,略显复杂。 试想如果能写成下面的样子,是不是更简单优雅 var p1 = products.Distinct(p => p.ID); var p2 = products.Distinct(p => p.Name); 使用一个简单的 lambda 作为参数,也符合 Linq 一贯的风格。 可通过 扩展方法 实现: Distinct 扩展方法 首先,创建一个通用比较的类,实现 IEqualityComparer<T> 接口: 1 using System; 2 using System.Collections.Generic; 3 using System.Runtime.CompilerServices; 4 using System.Linq; 5 6 public class CommonEqualityComparer<T, V> : IEqualityComparer<T> 7 { 8 private Func<T, V> keySelector; 9 10 public CommonEqualityComparer(Func<T, V> keySelector) 11 { 12 this.keySelector = keySelector; 13 } 14 15 public bool

【CF293B】Distinct Paths

两盒软妹~` 提交于 2020-02-06 17:00:37
题目 题目链接: https://www.luogu.com.cn/problem/CF293B 小首有一个 \(n\times m\) 的木板,一些块已经被涂上给出的 \(k\) 种颜色中的一种。你需要把每个没涂色的块涂色使得从左上角到右下角的每条路径都不会经过两个颜色一样的块。路径只能向右或向下走。 输出答案 \(\%1000000007\) 。 思路 显然,一个 \(n\times m\) 的矩阵的路径长度为 \(n+m-1\) ,那么 \(n\times m\) 的矩阵可以被 \(k\) 种颜色覆盖且每条路径均没有重复颜色的必要条件是 \(n+m-1\leq k\) 。 而这道题 \(k\leq 10\) ,所以其实这个矩阵最大就只有 \(30\) 格( \(5\times 6\) )。 那么就爆搜,需要加一下两个剪枝: 如果剩余格子比可以用的颜色多,直接返回。 如果一个颜色是第一次使用,那么如果再这个阶段有 \(k\) 种颜色是第一次使用,那么显然每一个第一次使用的颜色的方案数是一样的,直接 \(\times k\) 即可。 代码 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N=35,M=15,MOD=1000000007; int n,m