2014-07-22 74 views
1

我有一個Person table.Persons善於一些語言,我給他們weight.My表如下:行法如列數據庫查詢

Person 

ID Name Description 
1 Rodra Some.. 
2 Rakib Some.. 
3 Samsad Some.. 
4 Foysal Some.. 

Language 
TypeID TypeName 
1 C# 
2 Asp.Net 
3 Python 
4 JSP 
5 Java 
6 Jquery 
7 Android 

PersonSkill現在

ID PersonID TypeID Weight 
1 1   1  60 
2 1   3  50 
3 1   7  40 
4 2   1  80 
5 2   2  70 
6 3   1  90 
7 3   2  50 
8 4   1  60 
9 4   2  50 
10 4   6  40 
11 4   7  55 

我想要查詢那些知道c#(TypeId 1)> 65和Asp.net(TypeID 2)> 65的人。怎麼做?任何人都可以幫助我非常感謝。

回答

2
Select * 
FROM person 
WHERE EXISTS(SELECT * FROM PersonSkill WHERE PersonId = Person.Id AND TypeID = 1 AND Weight>65) 
AND EXISTS(SELECT * FROM PersonSkill WHERE PersonId = Person.Id AND TypeID = 2 AND Weight>65) 
0
select p.* from 
person p 
JOIN personSkill ps ON p.ID=ps.PersonID 
JOIN Language l ON l.TypeID=ps.TypeID 
WHERE (l.TypeName = 'c#' AND ps.weight>65) 
AND 
(l.TypeName = 'Asp.net' AND ps.weight>65)