distinct

SQL Server Generate UNIQUE random string

我怕爱的太早我们不能终老 提交于 2019-12-22 01:48:21
问题 With help of Zohar Answer, I got SQL function to generate random string but I am facing the problem with duplicate. Query Create FUNCTION [dbo].[MaskGenerator] ( @Prefix nvarchar(4000), -- use null or an empty string for no prefix @suffix nvarchar(4000), -- use null or an empty string for no suffix @MinLength int, -- the minimum length of the random part @MaxLength int, -- the maximum length of the random part @Count int, -- the maximum number of rows to return. Note: up to 1,000,000 rows

Distinct Subsequences

随声附和 提交于 2019-12-21 22:15:08
Description Given two strings S and T . Count the number of distinct subsequences of S which equals T . A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not) Example Example 1: Input: S = "rabbbit", T = "rabbit" Output: 3 Explanation: You could remove any 'b' in S, so there are 3 ways to get T. Example 2: Input: S = "abcd", T = "" Output: 1 Explanation: There is only 1 way to get T -

MySQL高级查询

流过昼夜 提交于 2019-12-21 16:48:46
在工作中经常需要汇总数据而不是将他们全部检索出来(实际数据本身:返回实际数据是对时间和处理资源的浪费),这种类型的检索有如下特点: 1:确定表中的行数(或满足某个条件或包含某个特定值的行数) 2:获得表中行组的和 3:找出表列(或所有行或某些特定的行)的最大值,最小值和平均值 聚集函数:运行在行组上,计算和返回单个值的函数; SQL聚集函数如图: 1,avg()函数通过对表中行数计数并计算特定列值之和,求得该列的平均值;avg()可用来返回所有平均值,也可以用来返回特定列的平均值; SELECT AVG(id) as age FROM person; avg()也可以用来确定特定列或行的平均值,如: SELECT AVG(id) as age FROM person WHERE age = 15; avg()只用来确定特定数值列的平均值,而且列名必须作为函数参数给出,为了获得多个列的平均值,必须使用多个avg()函数{avg()函数忽略列值为null的行}; 2,count()函数:确定表中行的数目或符合特定条件的行的数目. count()函数有两种使用方式: 1:使用count(*)对表中行的数目进行计数,不管表列中包含的是空值(null)还是非空值; 2:使用count(column)对特定列中具有值的行进行计数,忽略null值; SELECT count(*) as age

Mysql Select rows with same values in one column and different in another

試著忘記壹切 提交于 2019-12-21 12:17:00
问题 I'd really appreciate it if someone could validate my SQL query. For the following dataset: MD5 UserPK CategoryPK ADCDE 1 7 ADCDE 1 4 ADCDE 1 7 dffrf 1 7 dffrf 2 7 dffrf 2 6 dffrf 1 1 I'd like to select MD5 and CategoryPK where two or more rows exist with identical MD5 values, identical CatgegoryPK and two or more DIFFERENT UserPK values. In other words, I'd like to know the MD5 and categoryPK of all records where two or more different users (UserPK) have assigned the same category (UserPK)

mysql count unique row values

杀马特。学长 韩版系。学妹 提交于 2019-12-21 07:25:53
问题 TABLE quotation id clientid 1 25 2 25 3 25 4 25 5 26 How can I query how many different clients exist in TABLE quotation ? I don't want duplicate entries to be counted more than once. I need the answer to be 2 , in 1 row, because the only non-duplicated entries are ( 25 , 26 ). 回答1: select count(distinct clientid) from quotation read more 回答2: I tried the following on a MySQL 5.x database. id is an integer and clientid is an integer. I populated with two rows: id clientid 1 25 2 25 This SQL

Using Distinct with LINQ and Objects

半城伤御伤魂 提交于 2019-12-21 07:04:00
问题 Until recently, I was using a Distinct in LINQ to select a distinct category (an enum) from a table. This was working fine. I now need to have it distinct on a class containing a category and country (both enums). The Distinct isn't working now. What am I doing wrong? 回答1: I believe this post explains your problem: http://blog.jordanterrell.com/post/LINQ-Distinct()-does-not-work-as-expected.aspx The content of the above link can be summed up by saying that the Distinct() method can be

基于信息增益的决策树算法(附MATLAB代码)

浪子不回头ぞ 提交于 2019-12-21 05:51:51
基于信息增益的决策树算法(附MATLAB代码) 最近在学机器学习,本篇文章的内容正好是作业内容,所以拿来分享一下,顺便捋一下思路。下面内容只涉及到决策树学习基本算法(伪代码)、信息增益的计算和matlab代码实现。决策树算法原理不再赘述,请自行百度。水平有限,如有错误,欢迎指正! 一、决策树学习基本算法 二、 信息增益的计算 1.信息熵 “信息熵”(information entropy)是度量样本集合纯度最常用的一种指标,假定当前样本集合 D 中第 k 类样本所占的比例为 Pk ( k = 1,2,…,| Y | ),则D的信息熵定义为 Ent( D )的值越小, D 的纯度越高。 2.信息增益 假定离散属性 a 有 V 个可能的值 a1,a2,…,aV ,若使用 a 来对样本集D进行划分,则会产生 V 个分支节点,其中第 v 个分支节点包含了 D 中所有在属性 a 上取值为 av 的样本,记为 Dv ,这时可以计算出 Dv 的信息熵,同时考虑到不同的分支结点所包含的样本数不同,给分支结点赋予权重| Dv |/| D |,即样本数越多的分支结点的影响越大,于是可计算出用属性a对样本集D进行划分所获得的“信息增益”(information gain) 3.划分属性选择 一般而言,信息增益越大,则意味着使用属性 a 来进行划分所获得的“纯度提升”就越大,因此

JAVA8 stream接口 distinct,sorted,peek,limit,skip

匆匆过客 提交于 2019-12-21 04:46:10
下面,我们来看其他的剩余的一些中间操作,各自的作用,我也通过注释,做了解析,方法定义如下; //去重复 Stream<T> distinct(); //排序 Stream<T> sorted(); //根据属性排序 Stream<T> sorted(Comparator<? super T> comparator); //对对象的进行操作 Stream<T> peek(Consumer<? super T> action); //截断--取先maxSize个对象 Stream<T> limit(long maxSize); //截断--忽略前N个对象 Stream<T> skip(long n); 下面,我们用一些案例,对这些操作,做一些综合的演示 package com.taihao; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.stream.Stream; public class TestJava8 { public static List<Emp> list = new ArrayList<>(); static { list.add(new Emp("xiaoHong1",

Distinct count of multiple fields using mongodb aggregation

孤人 提交于 2019-12-21 04:41:15
问题 I'm trying to count distinct values of multiple fields By one MongoDB Aggregation query. So here's my data: { "car_type": "suv", "color": "red", "num_doors": 4 }, { "car_type": "hatchback", "color": "blue", "num_doors": 4 }, { "car_type": "wagon", "color": "red", "num_doors": 4 } I want a distinct count of each field: distinct_count_car_type=3 distinct_count_color=2 distinct_count_num_doors=1 I was able to group multiple fields and then do a distinct count but it could only give me a count on

SELECT DISTINCT cql ignores WHERE clause

怎甘沉沦 提交于 2019-12-21 03:32:57
问题 Executing two identical requests but the DISTINCT keyword gives unexpected results. Without the keyword, the result is ok but with DISTINCT, it looks like the where clause is ignored. Why ? Cqlsh version: Connected to Test Cluster at localhost:9160. [cqlsh 4.1.1 | Cassandra 2.0.6 | CQL spec 3.1.1 | Thrift protocol 19.39.0] Table considered: DESCRIBE TABLE events; CREATE TABLE events ( userid uuid, "timestamp" timestamp, event_type text, data text, PRIMARY KEY (userid, "timestamp", event_type)