cross-join

BigQuery argmax: Is array order maintained when doing CROSS JOIN UNNEST

匆匆过客 提交于 2020-01-05 08:36:18
问题 Question: In BigQuery, standard SQL, if I run SELECT * FROM mytable CROSS JOIN UNNEST(mytable.array) Can I be certain that the resulting row order is the same as the array order? Example: Let's say I have the following table mytable : Row | id | prediction 1 | abcd | [0.2, 0.5, 0.3] If I run SELECT * FROM mytable CROSS JOIN UNNEST(mytable.prediction) , can I be certain that the row order is the same as the array order? I.e. will the resulting table always be: Row | id | unnested_prediction 1

How do I cross join the date to a selection?

牧云@^-^@ 提交于 2019-12-25 01:36:38
问题 I need a query that will have the date, a user's name, and one of twelve operation_id's for that date. eg operations "id";"name"; "1";"LASER CUTTING" "2";"DEBURR" "3";"MACHINING" "4";"BENDING" "5";"PEM" "6";"WELDING" "7";"PAINT PREPARATION" "8";"PAINTING" "9";"SILKSCREEN PREPARATION" "10";"SILKSCREEN" "11";"ASSEMBLY - PACKAGING" "12";"LASER PREP"; and a users table bob jimmeh jimbo I have a cross join between those tables to get something like this: bob 1 bob 2 bob 3 bob 4 bob 5 bob 6 bob 7

Cross Join followed by Left Join

孤街浪徒 提交于 2019-12-24 17:57:40
问题 Is it possible to do a CROSS JOIN between 2 tables, followed by a LEFT JOIN on to a 3rd table, followed by possibly more left joins? I am using SQL Server 2000/2005. I am running the following query, which is pretty straightForward IMO, but I am getting an error. select P.PeriodID, P.PeriodQuarter, P.PeriodYear, M.Name, M.AuditTypeId, A.AuditId from Period P, Member M LEFT JOIN Audits A ON P.PeriodId = A.PeriodId WHERE P.PeriodID > 29 AND P.PeriodID < 38 AND M.AuditTypeId in (1,2,3,4) order

How to combine two unrelated tables in Mysql

為{幸葍}努か 提交于 2019-12-23 10:56:39
问题 There are two tables that are not related to each other(No foreign keys). How to show them together in MySQL? TABLE1 TABLE2 Result 回答1: You can use this too: SELECT t2.date, t1.name FROM table1 t1 CROSS JOIN table2 t2 回答2: Try This.. SELECT t2.date, t1.name FROM table1 t1, table2 t2 ORDER BY t1.name ASC 回答3: Try simply SELECT t2.date, t1.name FROM table1 t1, table2 t2 回答4: Try this: SELECT DATE, NAME FROM TABLE1, TABLE2 回答5: None of those will work. If you want to learn how to do this

Cross join behaviour (SQLServer 2008)

我与影子孤独终老i 提交于 2019-12-23 09:18:14
问题 I have been trying to track down a problem with a query I have. The query is actually generated by hibernate from HQL but the resulting SQL doesn't do what I expect. Modifying the SQL slightly produces the correct result but I'm not sure why the modification should make any difference. Original query (returns no rows) select sched.id, max(txn.dttm), acc.id from PaymentSchedulePeriod sched cross join PaymentSchedulePayment pay right outer join AccountTransaction txn on pay.accountTransactionFk

Memory efficient cartesian join in PySpark

大憨熊 提交于 2019-12-22 08:24:02
问题 I have a large dataset of string ids, that can fit into memory on a single node in my spark cluster. The issue is that it consumes most of the memory for a single node. These ids are about 30 characters long. For example: ids O2LWk4MAbcrOCWo3IVM0GInelSXfcG HbDckDXCye20kwu0gfeGpLGWnJ2yif o43xSMBUJLOKDxkYEQbAEWk4aPQHkm I am looking to write to file a list of all of the pairs of ids. For example: id1,id2 O2LWk4MAbcrOCWo3IVM0GInelSXfcG,HbDckDXCye20kwu0gfeGpLGWnJ2yif O2LWk4MAbcrOCWo3IVM0GInelSXfcG

Why do CROSS JOIN conditions not work in the 'ON' clause, only the WHERE clause?

若如初见. 提交于 2019-12-21 21:31:37
问题 I'm wondering why a conditional cross join must have the condition(s) specified in the WHERE clause, and why it doesn't work in the 'ON' clause. See link for compiled example: http://rextester.com/IKY8693 Business context: I need to generate a list of dates between a start and end date in order to fill in gaps in order to left join against a third table, such that zeroes/nulls are returned for a particular month. How I did this: Let's take for example a table of users, with YYYYMM start and

spark cross join,two similar code,one works,one not

天大地大妈咪最大 提交于 2019-12-20 07:07:57
问题 I have a following code: val ori0 = Seq( (0l, "1") ).toDF("id", "col1") val date0 = Seq( (0l, "1") ).toDF("id", "date") val joinExpression = $"col1" === $"date" ori0.join(date0, joinExpression).show() val ori = spark.range(1).withColumn("col1", lit("1")) val date = spark.range(1).withColumn("date", lit("1")) ori.join(date,joinExpression).show() The first join works,but the second has an error: Exception in thread "main" org.apache.spark.sql.AnalysisException: Detected implicit cartesian

Summarize the self-join index while avoiding cartesian product in R data.table

喜你入骨 提交于 2019-12-19 10:26:06
问题 With a 2-column data.table , I'd like to summarize the pairwise relationships in column 1 by summing the number of shared elements in column 2. In other words, how many shared Y elements does each pairwise combination of X-values have? For example, I can do this in a 2-step process, first doing a cartesian cross join, then summarizing it like so: d = data.table(X=c(1,1,1,2,2,2,2,3,3,3,4,4), Y=c(1,2,3,1,2,3,4,1,5,6,4,5)) setkey(d, Y) d2 = d[d, allow.cartesian=TRUE] d2[, .N, by=c("X", "i.X")] #

PostgreSQL Joining Between Two Values

两盒软妹~` 提交于 2019-12-18 09:24:35
问题 I have the following tables and am trying to look up county codes for a list of several hundred thousand cities. create table counties ( zip_code_from char(5) not null, zip_code_thru char(5) not null, county_code char(3) not null ); create table cities ( city text not null, zip_code char(5) not null ); My first approach was using a "between" in the join: select ci.city, ci.zip_code, co.county_code from cities ci join counties co on co.zip_code between ci.zip_code_from and ci.zip_code_thru I