DROP TABLE PERSON ; COMMIT; CREATE TABLE PERSON (ID INT, PARENT_ID INT); COMMIT;
INSERT INTO PERSON VALUES(1,1); INSERT INTO PERSON VALUES(2,1); INSERT INTO PERSON VALUES(3,2); INSERT INTO PERSON VALUES(4,3); INSERT INTO PERSON VALUES(6,5);
【在 n**m 的大作中提到】 : DROP TABLE PERSON ; : COMMIT; : CREATE TABLE PERSON (ID INT, PARENT_ID INT); : COMMIT; : : INSERT INTO PERSON VALUES(1,1); : INSERT INTO PERSON VALUES(2,1); : INSERT INTO PERSON VALUES(3,2); : INSERT INTO PERSON VALUES(4,3); : INSERT INTO PERSON VALUES(6,5);
w*y
9 楼
I am using T-SQL of SQL Server2k not DB2 a. With is not supported. :(
【在 n**m 的大作中提到】 : DROP TABLE PERSON ; : COMMIT; : CREATE TABLE PERSON (ID INT, PARENT_ID INT); : COMMIT; : : INSERT INTO PERSON VALUES(1,1); : INSERT INTO PERSON VALUES(2,1); : INSERT INTO PERSON VALUES(3,2); : INSERT INTO PERSON VALUES(4,3); : INSERT INTO PERSON VALUES(6,5);
w*y
10 楼
Just this seems to work too. SELECT CHILD.ID, CHILD.PARENT_ID FROM PERSON PARENT, PERSON CHILD WHERE PARENT.ID = CHILD.PARENT_ID
【在 n**m 的大作中提到】 : DROP TABLE PERSON ; : COMMIT; : CREATE TABLE PERSON (ID INT, PARENT_ID INT); : COMMIT; : : INSERT INTO PERSON VALUES(1,1); : INSERT INTO PERSON VALUES(2,1); : INSERT INTO PERSON VALUES(3,2); : INSERT INTO PERSON VALUES(4,3); : INSERT INTO PERSON VALUES(6,5);
n*m
11 楼
No, your can't work. I don't believe it can do recursive. :-)
【在 w*****y 的大作中提到】 : Just this seems to work too. : SELECT CHILD.ID, CHILD.PARENT_ID : FROM PERSON PARENT, PERSON CHILD : WHERE PARENT.ID = CHILD.PARENT_ID