distinct-values

Getting a distinct value across 2 union sql server tables

十年热恋 提交于 2019-12-05 00:21:07
I'm trying to get all distinct values across 2 tables using a union. The idea is to get a count of all unique values in the columnA column without repeats so that I can get a summation of all columns that contain a unique columnA. This is what I tried (sql server express 2008) select count(Distinct ColumnA) from ( select Distinct ColumnA as ColumnA from tableX where x = y union select Distinct ColumnA as ColumnA from tableY where y=z ) SELECT COUNT(distinct tmp.ColumnA) FROM ( (SELECT ColumnA FROM TableX WHERE x=y) UNION (SELECT ColumnA FROM TableY WHERE y=z) ) as tmp The extra distincts on

Distinct values in data bound combobox

一世执手 提交于 2019-12-04 17:39:21
I have a table Inventory(ItemId,Name,Size,Price,otherinfo) where ItemId is primary key and Name,Size,Price are unique. When I bind the combobox with Name all repeated names appear while i want each name to appear just once, same happens with Size. How to load unique values in combobox which is bound to a datasource? You can do this, (you may have to tweak it a bit to complie and work for you) ddlName.DataSource = items.Select(item=>item.Name).Distinct().ToList(); ddlName.DataBind(); ddlSize.DataSource = items.Select(item=>item.Size).Distinct().ToList(); ddlSize.DataBind(); ddlPrice.DataSource

How to aggregate count of unique values of categorical variables in R

北城以北 提交于 2019-12-04 09:57:29
Suppose I have a data set data : x1 <- c("a","a","a","a","a","a","b","b","b","b") x2 <- c("a1","a1","a1","a1","a1","a1","b1","b1","b2","b2") data <- data.frame(x1,x2) x1 x2 a a1 a a1 a a2 a a1 a a2 a a3 b b1 b b1 b b2 b b2 I want to find the number of unique values of x1 corresponding to x2 For example a has only 3 unique values ( a1,a2 and a3 ) and b has 2 values ( b1 and b2 ) I used aggregate(x1~.,data,sum) but it did not work since these are factors, not integers. Please help Try aggregate(x2~x1, data, FUN=function(x) length(unique(x))) # x1 x2 #1 a 3 #2 b 2 Or rowSums(table(unique(data)))

Creating distinct list from existing list in Java 7 and 8?

爱⌒轻易说出口 提交于 2019-12-04 08:57:52
问题 If I have: List<Integer> listInts = { 1, 1, 3, 77, 2, 19, 77, 123, 14, 123... } in Java what is an efficient way of creating a List<Integer> listDistinctInts containing only the distinct values from listInts ? My immediate thought is to create a Set<Integer> setInts containing all the values from listInts then call List<Integer> listDistinctInts = new ArrayList<>(setInts); But this seems potentially inefficient - is there a better solution using Java 7? I'm not using Java 8, but I believe

pyspark: count distinct over a window

时光毁灭记忆、已成空白 提交于 2019-12-03 17:07:33
问题 I just tried doing a countDistinct over a window and got this error: AnalysisException: u'Distinct window functions are not supported: count(distinct color#1926) Is there a way to do a distinct count over a window in pyspark? Here's some example code: from pyspark.sql.window import Window from pyspark.sql import functions as F #function to calculate number of seconds from number of days days = lambda i: i * 86400 df = spark.createDataFrame([(17, "2017-03-10T15:27:18+00:00", "orange"), (13,

pyspark: count distinct over a window

牧云@^-^@ 提交于 2019-12-03 05:28:17
I just tried doing a countDistinct over a window and got this error: AnalysisException: u'Distinct window functions are not supported: count(distinct color#1926) Is there a way to do a distinct count over a window in pyspark? Here's some example code: from pyspark.sql.window import Window from pyspark.sql import functions as F #function to calculate number of seconds from number of days days = lambda i: i * 86400 df = spark.createDataFrame([(17, "2017-03-10T15:27:18+00:00", "orange"), (13, "2017-03-15T12:27:18+00:00", "red"), (25, "2017-03-18T11:27:18+00:00", "red")], ["dollars", "timestampGMT

get Distinct Values with Sorted Data

拥有回忆 提交于 2019-12-03 02:21:54
I need a Query to get distinct keys with sorted on basis of score in Mongodb 1.6.5 I have records Like {key ="SAGAR" score =16 note ="test1" } {key ="VARPE" score =17 note ="test1" } {key ="SAGAR" score =16 note ="test2" } {key ="VARPE" score =17 note ="test2" } I need a query which sorts all records on score and returns me distinct key..... There is distinct command in mongodb: you can use distinct like this: db.test.distinct({"key":true,"score":true,"note":true}); the same in relational database: SELECT DISTINCT key,score,note FROM test; And than sort result by adding following code: .sort(

Creating distinct list from existing list in Java 7 and 8?

主宰稳场 提交于 2019-12-02 22:28:04
If I have: List<Integer> listInts = { 1, 1, 3, 77, 2, 19, 77, 123, 14, 123... } in Java what is an efficient way of creating a List<Integer> listDistinctInts containing only the distinct values from listInts ? My immediate thought is to create a Set<Integer> setInts containing all the values from listInts then call List<Integer> listDistinctInts = new ArrayList<>(setInts); But this seems potentially inefficient - is there a better solution using Java 7? I'm not using Java 8, but I believe using it I could do something like this(?): List<Integer> listDistinctInts = listInts.stream().distinct()

Mysql query to select Distinct Records on conditions?

白昼怎懂夜的黑 提交于 2019-12-02 14:56:38
问题 i have table structure like this.. ext_no , value .. i want to select distinct records on condition..like when count of ext_no is more than two and IF AND ONLY IF all that ext_no value is zero.. I Want Expected Result Given below...like.. how to write mysql query this this..? any help would be appreciated.. Thanks in advance.. Table Structure: CREATE TABLE `test` ( `ext_no` int(5) default NULL, `value` int(3) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table

Mysql query to select Distinct Records on conditions?

夙愿已清 提交于 2019-12-02 08:51:17
i have table structure like this.. ext_no , value .. i want to select distinct records on condition..like when count of ext_no is more than two and IF AND ONLY IF all that ext_no value is zero.. I Want Expected Result Given below...like.. how to write mysql query this this..? any help would be appreciated.. Thanks in advance.. Table Structure: CREATE TABLE `test` ( `ext_no` int(5) default NULL, `value` int(3) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `test` -- INSERT INTO `test` (`ext_no`, `value`) VALUES (12133, 0), (12133, 0), (12133, 0), (22222, 0),