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)
------解决方案--------------------
------解决方案--------------------
求交集
- SQL code
SELECT ConditionidFROM ConditionidWHERE ScreenId = 1INTERSECTSELECT ConditionidFROM ConditionidWHERE ScreenId = 4