-
1
- #1
FALCONSEYE
Programmer
I have the following table called tmp_p :
1 person1 1
2 person2 2
3 person2 10
4 person3 5
5 person3 1
6 person4 6
I am trying to write a join statement with the following conditions.
a. if a person has an accID 1, exclude him.
b. if a person has an accID 2 and 10, exclude him,
therefore, the sql statement should only return person6. I am having trouble writing a join statement. any help?
thanks in advance.
ColdFusion Ninja for hire.
Code:
CREATE TABLE xxx.TMP_P
(
PERSONID NUMBER,
NAME VARCHAR2(20 BYTE),
ACCID NUMBER
)
TABLESPACE xxx
PCTUSED 0
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
CREATE UNIQUE INDEX xxx.TMP_P_PK ON xxx.TMP_P
(PERSONID)
LOGGING
TABLESPACE xxx
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
NOPARALLEL;
ALTER TABLE xxx.TMP_P ADD (
CONSTRAINT TMP_P_PK
PRIMARY KEY
(PERSONID)
USING INDEX
TABLESPACE xxx
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
));
SET DEFINE OFF;
Insert into xxx.TMP_P
(PERSONID, NAME, ACCID)
Values
(1, 'person1', 1);
Insert into xxx.TMP_P
(PERSONID, NAME, ACCID)
Values
(2, 'person2', 2);
Insert into xxx.TMP_P
(PERSONID, NAME, ACCID)
Values
(3, 'person2', 10);
Insert into xxx.TMP_P
(PERSONID, NAME, ACCID)
Values
(4, 'person3', 5);
Insert into xxx.TMP_P
(PERSONID, NAME, ACCID)
Values
(5, 'person3', 1);
Insert into xxx.TMP_P
(PERSONID, NAME, ACCID)
Values
(6, 'person4', 6);
COMMIT;
1 person1 1
2 person2 2
3 person2 10
4 person3 5
5 person3 1
6 person4 6
I am trying to write a join statement with the following conditions.
a. if a person has an accID 1, exclude him.
b. if a person has an accID 2 and 10, exclude him,
therefore, the sql statement should only return person6. I am having trouble writing a join statement. any help?
thanks in advance.
ColdFusion Ninja for hire.