self-join

COUNT number of times prior to specified time, self-join?

﹥>﹥吖頭↗ 提交于 2020-06-01 05:13:06
问题 For simplicity let's assume I have two tables: billing with the following fields bill_id (primary, unique key, int), person_id , bill_date , and billing_detail containing bill_id and service_type . First of all I would like a list of clients ( person_id ) who were billed for a given range of services in a given period, so simply SELECT billing.person_id, billing.bill_date FROM billing INNER JOIN billing_detail ON billing.bill_id = billing_detail.bill_id WHERE billing_detail.service_type IN

Slow self-join delete query

笑着哭i 提交于 2020-02-25 09:42:11
问题 Does it get any simpler than this query? delete a.* from matches a inner join matches b ON (a.uid = b.matcheduid) Yes, apparently it does... because the performance on the above query is really bad when the matches table is very large. matches is about 220 million records. I am hoping that this DELETE query takes the size down to about 15,000 records. How can I improve the performance of the query? I have indexes on both columns. UID and MatchedUID are the only two columns in this InnoDB

Slow self-join delete query

六眼飞鱼酱① 提交于 2020-02-25 09:42:03
问题 Does it get any simpler than this query? delete a.* from matches a inner join matches b ON (a.uid = b.matcheduid) Yes, apparently it does... because the performance on the above query is really bad when the matches table is very large. matches is about 220 million records. I am hoping that this DELETE query takes the size down to about 15,000 records. How can I improve the performance of the query? I have indexes on both columns. UID and MatchedUID are the only two columns in this InnoDB

Slow self-join delete query

梦想的初衷 提交于 2020-02-25 09:41:57
问题 Does it get any simpler than this query? delete a.* from matches a inner join matches b ON (a.uid = b.matcheduid) Yes, apparently it does... because the performance on the above query is really bad when the matches table is very large. matches is about 220 million records. I am hoping that this DELETE query takes the size down to about 15,000 records. How can I improve the performance of the query? I have indexes on both columns. UID and MatchedUID are the only two columns in this InnoDB

Is Hibernate ManyToMany self-join possible for non-key columns? getting mappingException

耗尽温柔 提交于 2020-02-02 10:08:12
问题 I am having following problem. I have a user entity that has a many to many relationship with other user entities. Hence I want to make a self-join with manytomany annotation. This relation is based on already existing table that is used across the system so I cannot make changes to the DB at all. So we have 2 tables User(Id, ShortName) and UserLink(ParentId, ChildId). The annotation of ID is assigned to ShortName, but the actual keys in both User and UserLink are ID from User and ParentId

Is Hibernate ManyToMany self-join possible for non-key columns? getting mappingException

淺唱寂寞╮ 提交于 2020-02-02 10:08:05
问题 I am having following problem. I have a user entity that has a many to many relationship with other user entities. Hence I want to make a self-join with manytomany annotation. This relation is based on already existing table that is used across the system so I cannot make changes to the DB at all. So we have 2 tables User(Id, ShortName) and UserLink(ParentId, ChildId). The annotation of ID is assigned to ShortName, but the actual keys in both User and UserLink are ID from User and ParentId

sql query with self join

眉间皱痕 提交于 2020-01-17 05:11:22
问题 Given a table (TableA) that contains the following data; Id Date Status RecordId 1 01/06/11 2 REC001 2 01/06/11 2 REC002 3 01/06/11 2 REC003 4 01/07/11 1 REC001 How can I return all records with a status of 2 except records with a given RecordId where a status of 2 is followed by a record of 1 at a later date (and there are no further records with a status of 2. So for example, the query should return REC002 and REC003 as REC001 had a status of 2 in the past, but that was superseeded by

Self join to a table

有些话、适合烂在心里 提交于 2020-01-13 10:43:10
问题 I have a table like Employee ================== name salary ================== a 10000 b 20000 c 5000 d 40000 i want to get all the employee whose salary is greater than A's salary. I don't want to use any nested or sub query. It has been asked in an interview and hint was to use self join. I really can't figure out how to achieve the same. 回答1: select e1.* from Employee e1, Employee e2 where e2.name = 'a' and e1.salary > e2.salary Using self join select e1.* from Employee e1 join Employee e2

Oracle Self-Join on multiple possible column matches - CONNECT BY?

為{幸葍}努か 提交于 2020-01-13 05:07:09
问题 I have a query requirement from ----. Trying to solve it with CONNECT BY , but can't seem to get the results I need. Table (simplified): create table CSS.USER_DESC ( USER_ID VARCHAR2(30) not null, NEW_USER_ID VARCHAR2(30), GLOBAL_HR_ID CHAR(8) ) -- USER_ID is the primary key -- NEW_USER_ID is a self-referencing key -- GLOBAL_HR_ID is an ID field from another system There are two sources of user data (datafeeds)... I have to watch for mistakes in either of them when updating information.

Multiple Self-Join based on GROUP BY results

牧云@^-^@ 提交于 2020-01-09 08:17:57
问题 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 | |------------|-------------|---------|---------------------|------------------|----------------------|-------------|-------