我有一张表格,其中列出了会员潜水结果的结果。我需要拿出一个表格,只显示第一次通过潜水测试的个人,并将他们的资格包括在决赛桌中。
我的逻辑是,我会删除任何在考试历史中失败的人以及那些多次出现在列表中的人。
这就是我到目前为止所拥有的。我对 SQL 真的很陌生,所以如果看起来全错了,我真的很抱歉。
谢谢
SELECT b.branchmarina AS "Branch Suburb", m1.memsurname AS "Member Surname", m1.memfirstname AS "Member First Name", m2.memsurname AS "Mentor Surname", m2.memfirstname
AS "Mentor First Name", dt.dttestdate AS "Date", dt.DtQualLevel AS "Qualification" /*list of members who passed diving test on first attempt*/
FROM d_branch b, d_divetest dt, d_member m1, d_member m2
WHERE UPPER (dt.dttestresult)='PASS'
AND COUNT(DtMemberNo)<2
AND m2.MemMentorMemberNo=m1.memberno
AND m1.membranchno=b.branchno
AND dt.testresult = (SELECT *
FROM d_divetest dt1
WHERE UPPER (dt1.dttestresult)='PASS'
AND NOT EXISTS (UPPER (dt1.dttestresult)='FAIL'))
这是我正在使用的表:
DtTestDate DtMemberNo DtQualLevel DtTestResult DtReasonFailed
17-Apr-13 201 Beginner Pass
18-Apr-13 202 Advanced Pass
19-Apr-13 203 Expert Pass
20-Apr-13 204 Beginner Pass
21-Apr-13 205 Beginner Fail Not able to stabilise
26-Apr-13 205 Beginner Pass
22-Apr-13 206 Beginner Fail Not able to stabilise
27-Apr-13 206 Beginner Fail Not able to stabilise
27-May-13 206 Beginner Pass
27-Aug-13 206 Advanced Pass
23-Apr-13 207 Expert Pass
24-Apr-13 208 Beginner Pass
25-Apr-13 209 Advanced Pass
01-Dec-13 211 Beginner
02-Dec-13 212 Beginner
03-Dec-13 213 Beginner
04-Dec-13 214 Beginner
05-Dec-13 215 Beginner
27-Apr-13 226 Beginner Fail Weight belt not secured correctly
29-Apr-13 227 Advanced Fail Unable to complete test
30-Apr-13 228 Beginner Fail Not able to stabilise
如果有人有任何好的教程或建议,我将不胜感激。