self-join

Multiple Self-Join based on GROUP BY results

被刻印的时光 ゝ 提交于 2020-01-09 08:17:31
问题 I'm attempting to collect details about backup activity from a ProgreSQL DB table on a backup appliance (Avamar). The table has several columns including: client_name, dataset, plugin_name, type, completed_ts, status_code, bytes_modified and more. Simplified example: | session_id | client_name | dataset | plugin_name | type | completed_ts | status_code | bytes_modified | |------------|-------------|---------|---------------------|------------------|----------------------|-------------|-------

Calculating acceptance_ratio with LEFT JOIN and SELF JOIN and aggregate function

老子叫甜甜 提交于 2020-01-05 07:56:14
问题 Trying to calculate daily acceptance ratios from the 'connecting' table which has 4 fields with sample values: date action sender_id recipient_id '2017-01-05', 'request_link', 'frank', 'joe' '2017-01-06', 'request_link', 'sally', 'ann' '2017-01-07', 'request_link', 'bill', 'ted' '2017-01-07', 'accept_link', 'joe', 'frank' '2017-01-06', 'accept_link', 'ann', 'sally' '2017-01-06', 'accept_link', 'ted', 'bill' Because there are 0 accepts and 1 request on 01-05, its daily acceptance ratio should

Improving performance with a Similarity Postgres fuzzy self join query

丶灬走出姿态 提交于 2020-01-02 07:21:28
问题 I am trying to run a query that joins a table against itself and does fuzzy string comparison (using trigram comparisons) to find possible company name matches. My goal is to return records where the trigram similarity of one record's company name (ref_name field) matches another record's company name. Currently, I have my threshold set to 0.9 so it will only bring back matches that are very likely to contain the a similar string. I know that self joins can result in many comparisons by

how to write this self join query in mysql

自闭症网瘾萝莉.ら 提交于 2020-01-01 19:21:08
问题 Hello I have a table structure like this products_id | model_num | master_model_num 1 | cth001 | 0 2 | cth002 | 0 3 | cth003 | cth001 4 | cth004 | cth001 5 | cth005 | 0 6 | cth006 | cth002 My Problem I will provide the products_id to the table and it will get all product ids whoes master_model_num is equal to the model_num of the given products_id I have tried following query but it doen't generate the result that I want SELECT p.products_id FROM products p,products pp WHERE p.products_id=pp

“recursive” self join in data.table

荒凉一梦 提交于 2020-01-01 14:10:10
问题 I have a component list made of 3 columns: product, component and quantity of component used: a <- structure(list(prodName = c("prod1", "prod1", "prod2", "prod3", "prod3", "int1", "int1", "int2", "int2"), component = c("a", "int1", "b", "b", "int2", "a", "b", "int1", "d"), qty = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L)), row.names = c(NA, -9L), class = c("data.table", "data.frame")) prodName component qty 1 prod1 a 1 2 prod1 int1 2 3 prod2 b 3 4 prod3 b 4 5 prod3 int2 5 6 int1 a 6 7 int1 b 7 8

“recursive” self join in data.table

扶醉桌前 提交于 2020-01-01 14:09:27
问题 I have a component list made of 3 columns: product, component and quantity of component used: a <- structure(list(prodName = c("prod1", "prod1", "prod2", "prod3", "prod3", "int1", "int1", "int2", "int2"), component = c("a", "int1", "b", "b", "int2", "a", "b", "int1", "d"), qty = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L)), row.names = c(NA, -9L), class = c("data.table", "data.frame")) prodName component qty 1 prod1 a 1 2 prod1 int1 2 3 prod2 b 3 4 prod3 b 4 5 prod3 int2 5 6 int1 a 6 7 int1 b 7 8

MySQL A or B but NOT both

若如初见. 提交于 2019-12-31 05:09:12
问题 This seems like an easy query but I cannot seem to get it or relate it to other posts on stack overflow. Would anyone be able to explain... This is what I have so far, it is returning records for all bars where one or both people go. TBL frequents Schema - drinker VARCHAR(50) PK, bar VARCHAR(50) PK Bars which are frequented by John or Rebecca but not by both of them SELECT DISTINCT bar FROM frequents WHERE drinker = 'John' XOR drinker = 'Rebecca' AND bar NOT IN ( SELECT f1.bar FROM frequents

How to use Group By and self-join to return min, max, open, and close daily price restult set?

ぃ、小莉子 提交于 2019-12-30 11:19:05
问题 SOLVED All hail StackOverlow! While I was gone, people left 2 solutions (thanks guys--what is the protocol for handing out karma for two working solutions?) Here is the solution that I came back to post. it is derived from yet ANOTHER StackOver solution: How to fetch the first and last record of a grouped record in a MySQL query with aggregate functions? ...and my adaptation is: SELECT DATE_FORMAT(`DTE`, "%m/%d/%Y") AS trading_day, MIN(`PRICE`) AS min_price, MAX(`PRICE`) AS max_price,

Which query is more performant?

本小妞迷上赌 提交于 2019-12-26 07:20:18
问题 Suppose I have a self join query whose results are precisely the same for an inner join as they are for an outer join. In that case, is one more performant than another, or does it vary by what the query optimizer does? Typically I'd expect a LOJ to be less performant as it has to do all the work of an INNER JOIN plus the extra work of null-extending the results. But if that extra work isn't needed, should performance in theory be the same? I've tried this myself, but haven't noticed any

Which query is more performant?

杀马特。学长 韩版系。学妹 提交于 2019-12-26 07:19:25
问题 Suppose I have a self join query whose results are precisely the same for an inner join as they are for an outer join. In that case, is one more performant than another, or does it vary by what the query optimizer does? Typically I'd expect a LOJ to be less performant as it has to do all the work of an INNER JOIN plus the extra work of null-extending the results. But if that extra work isn't needed, should performance in theory be the same? I've tried this myself, but haven't noticed any