self-join

UPDATE rows with values from the same table

眉间皱痕 提交于 2019-12-08 09:23:39
问题 I have a table like this: +------+-------+ |ID | value | +------+-------+ | 1 | 150 | | 2 | | | 3 | | | 4 | | | 5 | 530 | | 6 | 950 | | 7 | 651 | +-------+------+ I want to copy the last 3 values and at the end my table will look like this: +------+-------+ |ID | value | +------+-------+ | 1 | 150 | | 2 | 530 | | 3 | 950 | | 4 | 651 | | 5 | 530 | | 6 | 950 | | 7 | 651 | +-------+------+ Is it possible? 回答1: Use a self-join : UPDATE mytable m SET value = m0.value FROM mytable m0 WHERE m.id =

How to implement self join in JPA?

江枫思渺然 提交于 2019-12-08 08:59:36
问题 I have a table as follow: create table ServiceType ( typeCode varchar(32), parentTypeCode varchar(32), description varchar(255), primary_key(typeCode)) I try to implement an entity for this table , the code snippet just like: @Entity @Table(name="ServiceType") public class ServcieType implements java.io.Serializable { @Id protected String typeCode; protected String description; @ManyToOne protected ServiceType parent; @OneToMany protected Set<ServiceType> children; .... following is the

postgres-xl self join cost 10 seconds when combine data

两盒软妹~` 提交于 2019-12-08 08:54:10
问题 My postgres-xl version was 9.5r1.5 stable. When query like below SELECT * FROM tests t1 LEFT JOIN tests t2 ON t1.id1 = t2.id2 WHERE t1.id1=10000; This query is simple, and just return one row. When I ran it in the data node, only cost 10ms. But cost 10020 ms in the coord node. I had tried some other query, and make sure that, when join the same table coord node cost 10 seconds. But if the query return nothing, it only cost 20ms in the coord node. So i think, it something wrong when coord node

UPDATE rows with values from the same table

假如想象 提交于 2019-12-08 05:04:28
I have a table like this: +------+-------+ |ID | value | +------+-------+ | 1 | 150 | | 2 | | | 3 | | | 4 | | | 5 | 530 | | 6 | 950 | | 7 | 651 | +-------+------+ I want to copy the last 3 values and at the end my table will look like this: +------+-------+ |ID | value | +------+-------+ | 1 | 150 | | 2 | 530 | | 3 | 950 | | 4 | 651 | | 5 | 530 | | 6 | 950 | | 7 | 651 | +-------+------+ Is it possible? Use a self-join : UPDATE mytable m SET value = m0.value FROM mytable m0 WHERE m.id = (m0.id - 3) -- define offset AND m.id BETWEEN 2 AND 4 -- define range to be affected AND m.value IS NULL; --

postgres-xl self join cost 10 seconds when combine data

夙愿已清 提交于 2019-12-08 04:56:28
My postgres-xl version was 9.5r1.5 stable. When query like below SELECT * FROM tests t1 LEFT JOIN tests t2 ON t1.id1 = t2.id2 WHERE t1.id1=10000; This query is simple, and just return one row. When I ran it in the data node, only cost 10ms. But cost 10020 ms in the coord node. I had tried some other query, and make sure that, when join the same table coord node cost 10 seconds. But if the query return nothing, it only cost 20ms in the coord node. So i think, it something wrong when coord node combine the data. can anyone tell me how to avoid this. thanks very much. Also try something like "SET

Data.table self-join on condition using a matrix

北慕城南 提交于 2019-12-08 04:13:11
问题 I am trying to do a join of a data.table with itself. The condition to join is based on the value of a column (not the key) being used to access a matrix. Each row has a date(in seconds) and records should only join with newest records (t1 cn<-unique(sdd$column) mat<-matrix(data=0,nrow=lde,ncol=lde,dimnames=list(cn,cn)) I am struggling with the documentation FAQ (including the SQL to data.table analogy) and the Beginner's Guide for data.table and multiple similar questions in this forum but I

LINQ: Self join query, how to accomplish this?

瘦欲@ 提交于 2019-12-07 17:10:56
问题 Can anyone help? I have 1 class, basically it holds Members and within that class is a List. The members i have in a List also... So basically it goes like this, I have 2 members and each member has a number of sessions. I wish to only return each member with 1 Session. I have done a LINQ query, but of course it doesn't work... I think i need to do a self join, any ideas? Basically my error is m doesn't exist in my subquery self join. var sessions = from m in this.members join s in ( from se

Understanding Self Join

纵饮孤独 提交于 2019-12-07 12:02:56
问题 I was practicing self join and here's a thing I do not understand in writing query. I have a table 'employee' The employee table contains three records. +-----+---------------+------------+ | id | employee | manager_id | +-----+---------------+------------+ | 1 | Ola | NULL | | 2 | Ahmed | 1 | | 3 | Tove | 1 | +----------+----------+------------+ Last column manager_id refers to the first column id making Ola manager of Ahmed and Tove. If I write the query like SELECT emp.employee as NAME,

Self-join on a table with ActiveRecord

北城以北 提交于 2019-12-07 02:44:20
问题 I have an ActiveRecord called Name which contains names in various Languages . class Name < ActiveRecord::Base belongs_to :language class Language < ActiveRecord::Base has_many :names Finding names in one language is easy enough: Language.find(1).names.find(whatever) But I need to find matching pairs where both language 1 and language 2 have the same name. In SQL, this calls for a simple self-join: SELECT n1.id,n2.id FROM names AS n1, names AS n2 WHERE n1.language_id=1 AND n2.language_id=2

Selecting rows from a table that have the same value for one field

安稳与你 提交于 2019-12-06 12:24:57
问题 I have a MySQL database with these two tables: Tutor(tutorId, initials, lastName, email, phone, office) Student(studentId, initials, lastName, email, tutorId) What is the query to return the initials and last names of any student who share the same tutor? I tried SELECT intials, lastName FROM Student WHERE tutorId = tutorId but that just returns the names of all students. 回答1: You'll have to join students against itself: SELECT s1.initials, s1.lastName FROM Student s1, Student s2 WHERE s1