日期:2014-05-18  浏览次数:20402 次

sql查询问题 请高手速达 在线等....
CREATE TABLE [dbo].[Conditionid](
[Id] [int] NOT NULL,
[ScreenId] [int] NULL,
[ConditionId] [int] NULL,
)


insert into Conditionid(Id,ScreenId,ConditionId)values(1,1,1);
insert into Conditionid(Id,ScreenId,ConditionId)values(2,4,1);
insert into Conditionid(Id,ScreenId,ConditionId)values(3,2,2);
insert into Conditionid(Id,ScreenId,ConditionId)values(4,5,2);
insert into Conditionid(Id,ScreenId,ConditionId)values(5,1,3);
insert into Conditionid(Id,ScreenId,ConditionId)values(6,4,3);

id ScreenId ConditionId
1 1 1
2 4 1
3 2 2
4 4 2
5 1 3
6 4 3


我要的意思是 根据ScreenID查询ConditionID 在ScreenID中包含(1,4) 的ConditionID (1,3)


------解决方案--------------------
你觉得结果应该是什么样,给个手算结果
------解决方案--------------------
SQL code

SELECT DISTINCT ConditionId 
FROM Conditionid WHERE ScreenId IN (1,4)

------解决方案--------------------
select * ftom [ConditionID] where ScreenID in(1,4) and ConditionId in (1,3)
------解决方案--------------------
探讨

引用:
引用:

引用:
select * ftom [ConditionID] where ScreenID in(1,4) and ConditionId in (1,3)


不不 理解的意思错了 条件 是ScreenID中有(1,4) 查询出的结果是ConditionID是1和3


3楼的结果是正确的

同时满足……

------解决方案--------------------
求交集
SQL code

SELECT Conditionid
FROM Conditionid
WHERE ScreenId = 1
INTERSECT
SELECT Conditionid
FROM Conditionid
WHERE ScreenId = 4