SQL查询语句--多表查询,请指教
首先说明一下本查询关联到的几个表:1、活动信息表activity: ([un]activityID[/un], activityName,……)
2、会员信息表member: ([un]userID[/un],userName,userpartDepartment,……)
3、报名信息表enrollment: ([un]enrollmentID[/un],userID,activityID,……)
4、团队报名表teamenrollment: ([un]teamenrollmentID[/un],principalID,activityID,……)
5、部门表partDepartment: ([un]userPartDepartment[/un],PartDepaName,……)
其中团队报名就是以集体名义报名,报名信息表是记录以个人名义报名的记录,会员和团队有属于某一部门。
有一个页面已成功统计并逐条展示某一个活动的团队报名信息情况,现在要从展示的团队报名信息中超链接显示本团队详细报名情况(即各人报名信息enrollment),在这个页面要同时显示以下信息:
(某活动的活动编号,活动名称; 团队负责人,负责人所在部门,团队名称; 及分条显示本团队报名本活动的所有个人的个人报名信息)
请高手指教查询语句怎么写,感激不尽~。或者帮忙查询我下面的编写错误在哪?
现在从上页面获得团队报名编号的值:
If (Request.QueryString("teamenrollmentID") <> "") Then
Rec1__MMColParam = Request.QueryString("teamenrollmentID")
查询语句如下:(为了方面看官我已调整段落格式)
Rs_enr.Sql=
"select activity.activityID,activity.activityName,teamenrollment.*,enrollment.*,
member.userID,member.userName,P_NAME,d_NAME
from enrollment,activity,member,teamenrollment,
(select principalID,username as P_NAME,userpartDepartment,partdepaname as d_NAME
from teamenrollment,member,partDepartment
where principalID=member.userID and
member.userpartDepartment=partDepartment.userpartDepartment)as b
where enrollment.activityID=activity.activityID and activity.activityID=teamenrollment.activityID and enrollment.userID=member.userID and b.principalID=teamenrollment.principalID and member.userpartDepartment=b.userpartDepartment and teamenrollmentID='" + Replace(Rec1__MMColParam, "'", "''") + "'
ORDER BY isparticipate,enrollment.enrollmentTime DESC"
属性名取得太长,请谅解。学习快乐~,期望得到你的指教,谢谢!