dzi*_*lla 6 sql ms-access ms-access-2007
我有一个数据库,其表具有标识符c1,c2,c3..etc ..
不是编写一堆包含OR
s 的查询,而是如何修改下面的查询,以便捕获以某个字母开头的所有记录?
SELECT
Person.spineinjuryAdmit,
tblComorbidity.comorbidityexplanation,
Count(tblComorbidity.comorbidityexplanation) AS CountOfcomorbidityexplanation
FROM tblKentuckyCounties
INNER JOIN (tblComorbidity
INNER JOIN (Person
INNER JOIN tblComorbidityPerson
ON Person.PersonID = tblComorbidityPerson.personID)
ON tblComorbidity.ID = tblComorbidityPerson.comorbidityFK)
ON tblKentuckyCounties.ID = Person.County
GROUP BY Person.spineinjuryAdmit,
tblComorbidity.comorbidityexplanation
HAVING (((Person.spineinjuryAdmit)="c1" Or
(Person.spineinjuryAdmit)="c2" Or
(Person.spineinjuryAdmit)="c3"));
Run Code Online (Sandbox Code Playgroud)
Rob*_*Rob 17
你试过用过LIKE
吗?举个例子:
SELECT * FROM patients WHERE lastName LIKE 'm%';
Run Code Online (Sandbox Code Playgroud)
这将返回patients.lastName
以'm'开头的记录.'%'字符可能是'*'用于访问,我不记得了.在某些数据库中,您还可以使用"_"来匹配单个字符(或者您添加的许多下划线).
SELECT Person.spineinjuryAdmit, tblComorbidity.comorbidityexplanation, Count(tblComorbidity.comorbidityexplanation) AS CountOfcomorbidityexplanation
FROM tblKentuckyCounties INNER JOIN (tblComorbidity INNER JOIN (Person INNER JOIN tblComorbidityPerson ON Person.PersonID = tblComorbidityPerson.personID) ON tblComorbidity.ID = tblComorbidityPerson.comorbidityFK) ON tblKentuckyCounties.ID = Person.County
GROUP BY Person.spineinjuryAdmit, tblComorbidity.comorbidityexplanation
HAVING (Person.spineinjuryAdmit LIKE "c*");
Run Code Online (Sandbox Code Playgroud)