cross-join

How to find rows>columns combinations with Cross Join? [SQL]

强颜欢笑 提交于 2021-02-08 11:13:10
问题 I want to create a combination of items from different categories ids. Can you help me? table +---------+-------------+------------+ | post_id | category_id | post_title | +---------+-------------+------------+ | 1 | 1 | Red | | 2 | 1 | Black | | 3 | 2 | Medium | | 4 | 3 | Male | | 5 | 3 | Female | +---------+-------------+------------+ The query results I want is as follows: Red-Medium-Male Black-Medium-Male Red-Medium-Female Black-Medium-Female For example, if there were items belonging to

efficient conditional cross join in data table

笑着哭i 提交于 2021-01-28 14:11:42
问题 EDITED (Sorry, I modified the code, it had an error that prevented reproduction.) I am trying to efficiently merge with a condition. The way I am doing it now is to cross-join (which I want to preserve) except I have one condition for a subset of the columns. Cross join function (from here) CJ.table.1 <- function(X,Y) setkey(X[,c(k=1,.SD)],k)[Y[,c(k=1,.SD)],allow.cartesian=TRUE][,k:=NULL] set.seed(1) #generate data x = data.table(t=rep(1:10,2), z=sample(1:10,20,replace=T)) x2 = data.table

Difference between cross product (cross join, Cartesian product) and natural join

喜欢而已 提交于 2021-01-27 07:55:48
问题 While writing in SQL, how would I know if I should use cross product (cross join, Cartesian product) or natural join? 回答1: CROSS JOIN creates all possible pairings of rows from two tables, whether they match or not. You don't use any join condition for a cross product, because the condition would always be true for any pairing. An example of using CROSS JOIN : you have tables of ShoeColors and ShoeSizes, and you want to know how many possible combinations there are. SELECT COUNT(*) FROM

Cohort-style Table (Diagonal Grid) in SQL

假如想象 提交于 2020-01-25 12:41:51
问题 I need to create a table that is like the image below: I can create the full 9 row table in sql using this code: select a.start_year, a.start_month, b.start_year as order_year, b.start_month as order_month from list a cross join list b; How can I remove the unwanted rows, or just not create them in the first place? 回答1: in ORACLE 11g SELECT * FROM ( SELECT y, x FROM table_name ) PIVOT ( MAX(z) FOR x IN (1, 2, 3) ) ORDER BY y; in SQL SERVER SELECT [y], [1], [2], [3] FROM [dbo].[table_name]

Trying to calculate quartiles in MDX

与世无争的帅哥 提交于 2020-01-11 13:32:53
问题 My data looks like this: ID |PersonID |CompanyID |DateID |Throughput |AmountType 33F467AC-F35B-4F24-A05B-FC35CF005981 |7 |53 |200802 |3 |0 04EE0FF0-511D-48F5-AA58-7600B3A69695 |18 |4 |201309 |5 |0 AB058AA5-6228-4E7C-9469-55827A5A34C3 |25 |69 |201108 |266 |0 with around a million rows. The columns names *ID refers to other tables, so they can be used as dimensions. I have an OLAP cube with the column Throughput as Measure and the rest as dimensions. I want to calculate Quartile 1 and 3 of the

Is there a way to perform a cross join or Cartesian product in excel?

筅森魡賤 提交于 2020-01-10 23:19:54
问题 At the moment, I cannot use a typical database so am using excel temporarily. Any ideas? The 回答1: You have 3 dimensions here: dim1 (ABC), dim2 (123), dim3 (XYZ). Here is how you make a cartesian product of 2 dimensions using standard Excel and no VBA: 1) Plot dim1 vertically and dim2 horizontally. Concatenate dimension members on the intersections: 2) Unpivoting data. Launch pivot table wizard using ALT-D-P (don't hold ALT, press it once). Pick "Multiple consolidation ranges" --> create a

mySql N to N double join with null - CROSS join from answer

荒凉一梦 提交于 2020-01-07 01:53:29
问题 I have two tables one called permissions and one called roles which are related through a third table called RolePermissions in a N-N relationship. Permissions id <- PK name Roles id <- PK name RolePermisions RoleId <-PK PermissionId <-PK isAllowed What I want is to get the full list of permissions of a specific role, and NULLs when there isn't a value in the RolePermission table for that Role. Left joins usually do the trick, but I can't work this one out. Basically let's say I have the