简体   繁体   English

MySQL搜索有多个条件

[英]mysql search with multiple conditions

Need a bit of help writing query as I have database containing 1000's records of records. 我的数据库包含1000条记录,需要一些帮助编写查询。

Basically I have a database that contains the following fields 基本上我有一个包含以下字段的数据库

entryID entryID

date 日期

toothNumber 牙齿编号

procedureName procedureName

studentName 学生姓名

tutorName tutorName

isolationSkill 隔离技能

isolationKnowledge 隔离知识

cavitySkill 空洞技能

cavityKnowledge 腔体知识

matrixSkill 矩阵技能

matrixKnowledge 矩阵知识

restorativeSkill 恢复性技能

restorativeKnowledge 恢复性知识

I want to write a query that searches all the records for a particular name(for example "Joe Bloggs") and the procedureName contains "Class II" 我想编写一个查询,以在所有记录中搜索特定名称(例如“ Joe Bloggs”),而procedureName包含“ Class II”

On top of that I want it to return the amount of times the Values N, B and C appear in the isolationskill - restorativeKnowldge columns. 最重要的是,我希望它返回值N,B和C在绝缘技能-restorativeKnowldge列中出现的次数。

So in the end I can see a list like this 所以最后我可以看到这样的列表

Hope this is making sense. 希望这是有道理的。 Let me know if you require any more information. 让我知道是否需要更多信息。

Thanks in advance 提前致谢

I think something like this would give you what you want, without you posting what you would like to see, kinda hard to tell, but this will pop out all the rows just like normal, and then give you a count field for each of the given Value n, B, C fields. 我认为类似这样的东西会给您想要的内容,而无需发布您想看到的内容,这很难说,但这将像平常一样弹出所有行,然后为每个行提供一个计数字段给定值n,B,C字段。 Apply this syntax multiple times to get the exact results you are looking for on the different fields. 多次应用此语法,以获得在不同字段上寻找的确切结果。

SELECT 
entryID, 
date, 
procedurename, 
studentName, 
tutorName, 
restorativeSkill, 
isolationKnowledge, 
cavitySkill, 
cavityKnowledge, 
matrixSkill, 
matrixKnowledge,
restorativeknowledge,
SUM(IF(isolationSkill = 'N', 1,0)), 
SUM(IF(restorativeKnowldge = 'B', 1,0)) FROM records 
WHERE procedureName = 'Class II' and Name = "Joe Bloggs";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM