CREATE TABLE T_TYPE
(
T_TYPE_ID NUMBER,
T_TYPE_NAME VARCHAR2(20)
);
INSERT INTO T_TYPE
SELECT 1, '苹果' FROM DUAL UNION ALL
SELECT 2, '香蕉' FROM DUAL;
CREATE TABLE T_INFO
(
T_PERSON_ID NUMBER,
T_PERSON_NAME VARCHAR(20),
T_TYPE_ID DECIMAL
);
INSERT INTO T_INFO
SELECT 1, '张三', 1 FROM DUAL UNION ALL
SELECT 1, '张三', 2 FROM DUAL UNION ALL
SELECT 2, '李四', 1 FROM DUAL
/*
求T_INFO表中T_PERSON_ID的T_TYPE_ID在表T_TYPE中都有的人
结果是张三
*/
分享到:
------解决方案-------------------- SELECT A.T_PERSON_NAME FROM T_INFO A,T_TYPE B,T_TYPE C
WHERE A.T_PERSON_ID=B.T_TYPE_ID AND A.T_TYPE_ID=C.T_TYPE_ID ------解决方案--------------------
select T_PERSON_NAME
from t_info
group by T_PERSON_NAME
having count(*) = (select count(*) from t_type)