在上面的图片我有6个领域,从他们我的搜索可以是6个领域的任何组合,它只能是 class
或者 class-section
或者 class-section-caste
如何编写独立于参数数量的单个查询。
在where子句中可以用and或吗
class=Frist or (class=first and section=A) or (class=first and section=A and gender=Male)
有没有可能做到这一点,或者有没有更好的办法来实现这一点。
编辑请查看查询
query = currentSession.createQuery("select s.studentAdmissionId as studentAdmissionId, s.adsmissionNum as studentAdmnNum ,s.firstname as studentFirstName , s.lastname as studentLastName , s.adharNum as adharNumber ,"
+ " peDe.contactNum as mobileNumber ,m.className as className ,sec.sectionName as sectionName from StudentDetails s, StudentPresentClassDetails pd, MasterCampusClass m ,"
+ "MasterCampusSection sec , StudentParentDetails peDe where s.studentAdmissionId = peDe.studentAdmissionId and (pd.studentAdmissionId = s.studentAdmissionId and pd.classId=m.classId) and (pd.studentAdmissionId = s.studentAdmissionId and pd.presentSectionId = sec.sectionId) and pd.classId = :classId or sec.sectionId .........");
3条答案
按热度按时间mgdq6dx11#
等等。简洁的sql
vulvrdjw2#
您可以使用多个if语句来创建查询:
gorkyyrv3#
@米ạ新罕布什尔州ế恩圭ễn谢谢你的示例代码。
代码中有一些错误。我写的代码引用@mạ新罕布什尔州ế恩圭ễn样本代码
给你
感谢每一个人!