本文介绍了如何根据需要从SQL Server Ce数据库检索记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我在从SQL Server精简版数据库检索记录时遇到问题.
我有两个表:-
1.名称= GroupTask,PK = GTaskID
GTaskID | GTaskSubject | GTaskBody | GTaskDeadline |
---|---|---|---|
1001 | 做某事 | Bla bla bla ... | 2011/3/31 |
2.Name = GroupTaskDetails,FK = GTaskID,UserName
GTaskID | UserName |
---|---|
1001 | A |
1001 | B |
1001 | C |
上面有很多行...
现在:-
1.
我想从GroupTask表中获取*,用于A,B和A上的此类任务; C都是
已分配.
2.
我想从GroupTask表中获取*,用于A,B和A上的此类任务; Z全部分配.
当我使用:-用户名in(''A'',``B'',''Z'')返回1001但Z不在1001
我需要AND条件而不是OR条件,这是IN谓词的作用.
有什么主意吗?
预先感谢.
Hello Every One, I have a problem in retrieving records from SQL Server compact edition database.
I have two tables:-
1. Name= GroupTask , PK=GTaskID
GTaskID | GTaskSubject | GTaskBody | GTaskDeadline |
---|---|---|---|
1001 | Do Somthing | Bla bla bla... | 3/31/2011 |
2.Name=GroupTaskDetails , FK=GTaskID ,UserName
GTaskID | UserName |
---|---|
1001 | A |
1001 | B |
1001 | C |
many rows are there like above...
Now:-
1.
I want to get * from GroupTask table for such tasks on which A,B & C all are
assigned.
2.
I want to get * from GroupTask table for such tasks on which A,B & Z all are assigned.
when I use:- username in(''A'',''B'',''Z'') it returns 1001 but Z is not on 1001
I need AND condition not OR Condition that is what IN predicate does.
Any idea?
Thanks in advance.
推荐答案
SELECT *
FROM GroupTask gt
WHERE EXISTS (SELECT * FROM GroupTaskDetails WHERE GTaskID = gt.GTaskID AND UserName = ''A'')
AND
EXISTS (SELECT * FROM GroupTaskDetails WHERE GTaskID = gt.GTaskID AND UserName = ''B'')
AND
EXISTS (SELECT * FROM GroupTaskDetails WHERE GTaskID = gt.GTaskID AND UserName = ''Z'')
这将产生预期的结果.我唯一不知道的是SQL Server CE是否允许子选择.
干杯,
This will yield the expected result. The only thing I don''t know is if subselects are allowed on SQL Server CE.
Cheers,
这篇关于如何根据需要从SQL Server Ce数据库检索记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!