0

メンバーのダイビング結果が一覧表示された表があります。最初にダイビング テストに合格した個人のみを表示するテーブルを作成し、その資格を最終テーブルに含める必要があります。

私の論理では、受験履歴に失敗した人や、リストに複数回表示されている人を削除します。

これは私がこれまでに持っているものです。私は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

誰かが良いチュートリアルや提案を持っていれば、私はそれを感謝します.

4

2 に答える 2

0

ニーズに合わせてこれを変更します。

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
INNER JOIN 
    d_member m1
ON 
    m1.membranchno = b.branchno
INNER JOIN 
    d_member m2
ON
    m2.MemMentorMemberNo = m1.memberno
INNER JOIN 
    d_divetest dt
ON 
    m2.memberno = dt.dtMemberNo
WHERE UPPER(dt.dttestresult) = 'PASS'
   AND (select count(*) from d_divetest dd where dd.dtMemberNo = dt.MemberNo)=1
于 2013-11-04T10:34:52.787 に答える