cross-join

Google App Script returns array over multiple rows

99封情书 提交于 2019-12-08 05:02:33
问题 Summary I'm new to Google Apps Script but I've spent quite a bit of time researching and have come up empty. Basically I'm trying to replicate a cross-join functionality of SQL. I have 2 tables, a calendar table with 12 months, and a customer table with 3 customers. The customer table is populated from a Google form, and will have new customers added going forward. For my reporting, I need the customer data to be at a monthly grain. Therefore I want to cross-join the customer data with the

inner join with multiple conditions r data table

雨燕双飞 提交于 2019-12-07 16:49:58
问题 I am trying to do an inner join using data table that has multiple, fairly dynamic conditions. I am getting tripped up on the syntax. First, I create two objects, x and x2 that I want to do an inner join with. set.seed(1) #generate data x = data.table(CJ(t=1:10, d=1:3,p1s=seq(1,3,by=0.1),p1sLAST=seq(1,3,by=0.1))) x[d==1,p1sLAST:=3] x=x[p1s<=p1sLAST] x2 = data.table(CJ(tprime=1:10, p1sLASTprm=seq(1,3,by=0.1))) With the objects: > x t d p1s p1sLAST 1: 1 1 1.0 3.0 2: 1 1 1.0 3.0 3: 1 1 1.0 3.0 4

Row Aggregation after Cross Join in BigQuery

末鹿安然 提交于 2019-12-06 11:12:31
问题 Say you have the following table in BigQuery: A = user1 | 0 0 | user2 | 0 3 | user3 | 4 0 | After a cross join, you have dist = |user1 user2 0 0 , 0 3 | #comma is just showing user val seperation |user1 user3 0 0 , 4 0 | |user2 user3 0 3 , 4 0 | How can you perform row aggregation in BigQuery to compute pairwise aggregation across rows. As a typical use case, you could compute the euclidean distance between the two users. I want to compute the following metric between the two users: sum(min

Cross join N sets of rows in same table

▼魔方 西西 提交于 2019-12-06 08:16:53
问题 I have a generic "Dimension" and "DimensionMember" tables. CREATE TABLE [dbo].[Dimension] ( [ID] [int] NOT NULL IDENTITY(1, 1), [Label] [nvarchar] (255) ) CREATE TABLE [dbo].[DimensionMember] ( [ID] [int] NOT NULL IDENTITY(1, 1), [Label] [nvarchar] (255) NOT NULL, [DimensionID] [int] NOT NULL ) GO ALTER TABLE [dbo].[DimensionMember] ADD CONSTRAINT [FK_DimensionMember_DimensionID_Dimension_ID] FOREIGN KEY ([DimensionID]) REFERENCES [dbo].[Dimension] ([ID]) These table store a large number of

mysql cross join, but without duplicated pair?

自古美人都是妖i 提交于 2019-12-06 01:12:31
问题 Let's say I have the following row in my table table rows id 63 64 65 66 67 68 if I run the following query, I get 30 rows. SELECT r1.id, r2,id FROM rows AS r1 CROSS JOIN rows AS r2 WHERE r1.id!=r2.id result: 63 64 65 64 66 64 67 64 68 64 64 63 65 63 66 63 67 63 68 63 63 65 64 65 66 65 67 65 68 65 63 66 64 66 65 66 67 66 68 66 63 67 64 67 65 67 66 67 68 67 63 68 64 68 65 68 66 68 67 68 how would I get the following result instead of the above? 63,64 63,65 63,66 63,67 63,68 64,65 64,66 64,67

DAX / PowerPivot query functions to spread aggregated values over time period

倾然丶 夕夏残阳落幕 提交于 2019-12-05 00:54:14
问题 I’m trying to work out the DAX expression [for MS PowerPivot in Excel 2010] to evenly distribute the sum of a value across the range it’s applied to, and re-sum that up for a given time span/period. It’s trivial to cross-apply in SQL server, though with every attempt, end up with the same wrong result. I’ve got the output from MS Project saved as Excel and imported/transformed using PowerQuery, so the start and finish/end dates are proper dates, the {X}h and {Y}d are integers, and the

PostgreSQL LEFT OUTER JOIN query syntax

喜你入骨 提交于 2019-12-05 00:50:11
问题 Lets say I have a table1 : id name ------------- 1 "one" 2 "two" 3 "three" And a table2 with a foreign key to the first: id tbl1_fk option value ------------------------------- 1 1 1 1 2 2 1 1 3 1 2 1 4 3 2 1 Now I want to have as a query result: table1.id | table1.name | option | value ------------------------------------- 1 "one" 1 1 2 "two" 1 1 3 "three" 1 "one" 2 1 2 "two" 3 "three" 2 1 How do I achieve that? I already tried: SELECT table1.id, table1.name, table2.option, table2.value FROM

Add missing rows to data.table according to multiple keyed columns

心已入冬 提交于 2019-12-04 21:49:18
问题 I have a data.table object that contains multiple columns that specify unique cases. In the small example below, the variables " name ", " job ", and " sex " specify the unique IDs. I would like to add missing rows so that each each case has a row for each possible instance of another variable, " from " (similar to expand.grid ). library(data.table) set.seed(1) mydata <- data.table(name = c("john","john","john","john","mary","chris","chris","chris"), job = c("teacher","teacher","teacher",

How avoid cross join in hive?

混江龙づ霸主 提交于 2019-12-04 14:51:22
I have two tables. one includes 1 million records, the other includes 20 million records. table 1 value (1, 1) (2, 2) (3, 3) (4, 4) (5, 4) .... table 2 value (55, 11) (33, 22) (44, 66) (22, 11) (11, 33) .... I need to use the value in tables 1 to multiply by the value in table 2, get the rank of the result, and get top 5 in the rank. their result would be like: value from table 1, top 5 for each value in table 1 (1, 1), 1*44 + 1*66 = 110 (1, 1), 1*55 + 1*11 = 66 (1, 1), 1*33 + 1*22 = 55 (1, 1), 1*11 + 1*33 = 44 (1, 1), 1*22 + 1* 11 = 33 ..... I tried to use cross join in hive. but I always get

Cross join N sets of rows in same table

点点圈 提交于 2019-12-04 13:46:03
I have a generic "Dimension" and "DimensionMember" tables. CREATE TABLE [dbo].[Dimension] ( [ID] [int] NOT NULL IDENTITY(1, 1), [Label] [nvarchar] (255) ) CREATE TABLE [dbo].[DimensionMember] ( [ID] [int] NOT NULL IDENTITY(1, 1), [Label] [nvarchar] (255) NOT NULL, [DimensionID] [int] NOT NULL ) GO ALTER TABLE [dbo].[DimensionMember] ADD CONSTRAINT [FK_DimensionMember_DimensionID_Dimension_ID] FOREIGN KEY ([DimensionID]) REFERENCES [dbo].[Dimension] ([ID]) These table store a large number of dimensions and dimension members. I want to cross join dimension members from variable number of