mysql,sql,self-join,cross-product

You are getting duplicated columns because as you have it, you are querying from T1 AND T2. So unless you explicitly say show me only T1.* it will grab columns from BOTH table alias references. Since your query is doing an OR on the dates, you are probably going to...

r,matrix,unique,combinations,cross-product

Try lst <- split(df$Users, df$Products) ln <- length(lst) m1 <- matrix(0, ln,ln, dimnames=list(names(lst), names(lst))) m1[lower.tri(m1, diag=FALSE)] <- combn(seq_along(lst), 2, FUN= function(x) length(unique(unlist(lst[x])))) m1[upper.tri(m1)] <- m1[lower.tri(m1)] m1 # Product a Product b Product c #Product a 0 2 3 #Product b 2 0 3 #Product c 3 3 0 Or using...

A Join On ISNULL(Parent,ID) for the table with itself should return the desired result. declare @a Table (ID varchar(10),Parent Varchar(10)) Insert into @a Values ('A',NULL) ,('B' , 'A'),('C','A'),('E',NULL) ,('F','E') Select a.ID,b.ID as GroupMember from @a a JOIN @a b ON ISNULL(a.Parent,a.ID)=ISNULL(b.Parent,b.ID) ...

matlab,matrix,vector,vectorization,cross-product

First, make sure you read the documentation of cross very carefully when dealing with matrices: It says: C = cross(A,B,DIM), where A and B are N-D arrays, returns the cross product of vectors in the dimension DIM of A and B. A and B must have the same size, and...

Having m <- melt(tcrossprod(df$b,1/df$b)), you can simply do: subset(m,X1>X2) # X1 X2 value #2 2 1 0.5 #3 3 1 0.4 #4 4 1 1.0 #7 3 2 0.8 #8 4 2 2.0 #12 4 3 2.5 ...