データベースの複数のテーブルからデータを取り出すように設計されたSQLスクリプトがあります。原則としてこれは動作していますが、私は次のような動作を追加しようとしています: シナリオの場合、3つの可能なオプションに対してコースタイトルがチェックされています。それがタイトルに存在する場合、別のデータベースをチェックし、特定のAssessorTypeを持つTOP 1 AssessorID(DESC終了日でソート)を検索します。このタイプのアイディアは、そのタイプのコースのアセスメントです。可能な3つのオプションが存在しない場合は、そのコースに対してAタイプのAssessorを引っ張ってください。典型的には1人の学習者3に対して4コースタイプAの査定タイプEまたはFおよび1のためかもしれないがあるかもしれないスクリプトが生成SQLスクリプトの問題 - 複製
ただし結果何が起こるかは、それが関連する各コース別名
ため重複する行を作成することです学習者A - コースA - AssessorType
学習者A - Bコース - AssessorType E
私は達成するために探しています何が1本の1コースのラインが、そのコースの正しい単一assessortypeですときに基づいて。
CASE WHEN TRAINEE_LLWR_ACT.TITLE_LA IN ('%CG COMM%','%CG AON%','%CG DIG LIT%') THEN
(SELECT TOP (1) TRASSESSOR.ASSESSORID
FROM TRAINEE INNER JOIN
TRASSESSOR ON TRAINEE.TRAINEEID = TRASSESSOR.TRAINEEID
WHERE (TRASSESSOR.ASSESSORTYPE = 'E' OR TRASSESSOR.ASSESSORTYPE = 'F') AND (TRASSESSOR.TRAINEEID = TRAINEE.TRAINEEID)
ORDER BY TRASSESSOR.ENDDATE DESC)
ELSE TRASSESSOR.ASSESSORID END AS [Courses/Course/MISAssessorID]
私が加入するが、私は」とそのおそらくを行うには確信している:ここで
は、ここで問題にSELECT DISTINCT
TOP (100) PERCENT TRAINEE.LLWR_LEARN_ID AS MISLearnerID,
REPLACE(TRAINEE.FIRSTNAME, ' ', '.')+REPLACE(TRAINEE.LASTNAME,' ','') AS UserID,
TRAINEE.FIRSTNAME AS Forename,
TRAINEE.LASTNAME AS Surname,
TRAINEE.ADDRESS1 AS HomeAddressLine1,
TRAINEE.LLWR_LEARN_ID AS StudentID,
TRAINEE.ADDRESS2 AS HomeAddressLocality,
TRAINEE.POSTTOWN AS HomeAddressTown,
TRAINEE.COUNTY AS HomeAddressCounty,
TRAINEE.UNIQUELEARNERNUMBER AS ULN,
TRAINEE.POSTCODE AS HomeAddressPostCode,
TRAINEEPOT2.LLWR_DISABLE2 AS LDisability,
CASE WHEN TRAINEEPOT2.LLWR_NUM_STRT = '1' THEN 'Entry Level 1'
WHEN TRAINEEPOT2.LLWR_NUM_STRT = '1' THEN 'Entry Level 1'
WHEN TRAINEEPOT2.LLWR_NUM_STRT = '2' THEN 'Entry Level 2'
WHEN TRAINEEPOT2.LLWR_NUM_STRT = '3' THEN 'Entry Level 3'
WHEN TRAINEEPOT2.LLWR_NUM_STRT = '5' THEN 'Level 1'
WHEN TRAINEEPOT2.LLWR_NUM_STRT = 'D' THEN 'Level 2'
WHEN TRAINEEPOT2.LLWR_NUM_STRT = 'F' THEN 'Level 3'
END AS InitialAssessmentNumeracy,
CASE WHEN TRAINEEPOT2.LLWR_LITY_SRT = '1' THEN 'Entry Level 1'
WHEN TRAINEEPOT2.LLWR_LITY_SRT = '2' THEN 'Entry Level 2'
WHEN TRAINEEPOT2.LLWR_LITY_SRT = '3' THEN 'Entry Level 3'
WHEN TRAINEEPOT2.LLWR_LITY_SRT = '5' THEN 'Level 1'
WHEN TRAINEEPOT2.LLWR_LITY_SRT = 'D' THEN 'Level 2'
WHEN TRAINEEPOT2.LLWR_LITY_SRT = 'F' THEN 'Level 3'
END AS InitialAssessmentLiteracy,
CASE WHEN TRAINEEINFO.U_DIGLIT = 'E1' THEN 'Entry Level 1'
WHEN TRAINEEINFO.U_DIGLIT = 'E2' THEN 'Entry Level 2'
WHEN TRAINEEINFO.U_DIGLIT = 'E3' THEN 'Entry Level 3'
WHEN TRAINEEINFO.U_DIGLIT = 'L1' THEN 'Level 1'
WHEN TRAINEEINFO.U_DIGLIT = 'L2' THEN 'Level 2'
WHEN TRAINEEINFO.U_DIGLIT = 'L3' THEN 'Level 3'
WHEN TRAINEEINFO.U_DIGLIT = 'na' THEN 'Not Applicable'
END AS InitialAssessmentICT,
TRAINEE.EMAIL, TRAINEE.TELEPHONE AS TelNum,
TRAINEE.DOB,
TRAINEE.NINUMBER AS NationalInsuranceNo,
(SELECT TOP (1) LONGSTRING
FROM LOOKUP
WHERE
(TABLENAME = 'TRAINEE') AND (FIELDNAME = 'GENDER') AND (SHORTSTRING = TRAINEE.GENDER)) AS Sex,
TRAINEE.MOBILE,
TREMPLOYER.EMPLOYERID AS MISEmployerID,
TRAINEE_LLWR_ACT.LAIM_REF AS [Courses/Course/LadCode],
TRAINEE_LLWR_ACT.TITLE_LA AS [Courses/Course/CourseName],
TRAINEE_LLWR_ACT.EENDDATE AS [Courses/Course/CourseEndDate],
TRAINEEPOT.STARTDATE AS [Courses/Course/CourseStartDate],
TRAINEE_LLWR_ACT.TERMDATE AS [Courses/Course/ActualEndDate], TRAINEE_LLWR_ACT.REGNUMBER AS [Courses/Course/RegistrationNumber],
CASE WHEN TRAINEE_LLWR_ACT.TITLE_LA IN ('%CG COMM%','%CG AON%','%CG DIG LIT%') THEN
(SELECT TOP (1) TRASSESSOR.ASSESSORID
FROM TRAINEE INNER JOIN
TRASSESSOR ON TRAINEE.TRAINEEID = TRASSESSOR.TRAINEEID
WHERE (TRASSESSOR.ASSESSORTYPE = 'E' OR TRASSESSOR.ASSESSORTYPE = 'F') AND (TRASSESSOR.TRAINEEID = TRAINEE.TRAINEEID)
ORDER BY TRASSESSOR.ENDDATE DESC)
ELSE TRASSESSOR.ASSESSORID END AS [Courses/Course/MISAssessorID],
CASE WHEN TRAINEE_LLWR_ACT.COMPSTAT = 1 THEN 'IT'
WHEN TRAINEE_LLWR_ACT.COMPSTAT = 2 THEN 'CM'
WHEN TRAINEE_LLWR_ACT.COMPSTAT = 3 THEN 'EL'
WHEN TRAINEE_LLWR_ACT.COMPSTAT = 4 THEN 'TR'
WHEN TRAINEE_LLWR_ACT.COMPSTAT = 5 THEN 'TS'
WHEN TRAINEE_LLWR_ACT.COMPSTAT = 6 THEN 'EL' END AS [Courses/Course/Status]
FROM TRAINEE INNER JOIN
TREMPLOYER ON TRAINEE.TRAINEEID = TREMPLOYER.TRAINEEID INNER JOIN
TRAINEE_LLWR_ACT ON TRAINEE.TRAINEEID = TRAINEE_LLWR_ACT.TRAINEEID INNER JOIN
TRASSESSOR ON TRAINEE.TRAINEEID = TRASSESSOR.TRAINEEID INNER JOIN
TRAINEEINFO ON TRAINEE.TRAINEEID = TRAINEEINFO.TRAINEEID INNER JOIN
TRAINEEPOT ON TRAINEE.TRAINEEID = TRAINEEPOT.TRAINEEID INNER JOIN
TRAINEEPOT2 ON TRAINEE.TRAINEEID = TRAINEEPOT2.TRAINEEID
WHERE (TRAINEEINFO.U_E_PORTFOLIO = 'Yes') AND (TRAINEE.ADMINCENTREID = '0003') AND
(TRAINEE_LLWR_ACT.DELIVERY = '09' OR
TRAINEE_LLWR_ACT.DELIVERY = '03' OR
TRAINEE_LLWR_ACT.DELIVERY = '02') AND (TRASSESSOR.ENDDATE =
(SELECT MAX(ENDDATE) AS Expr1
FROM TRASSESSOR AS TRASSESSOR_1
WHERE (TRAINEE.TRAINEEID = TRAINEEID))) AND
((SELECT TOP (1) EMPLOYERID
FROM TREMPLOYER AS TREMPLOYER_1
WHERE (TRAINEEID = TRAINEE.TRAINEEID)
ORDER BY STARTDATE DESC) = TREMPLOYER.EMPLOYERID)
ORDER BY surname
特定のケースを実行しているされている完全なスクリプトです私が何をする必要があるかを理解するためにSQLで十分に修飾されていません。どんな助けもありがとう!
あなたの例をAコースで与えますか?AssessorType AまたはAssessorType Eを使用しますか? – Simon
どの[DBMS](https://en.wikipedia.org/wiki/DBMS)製品を使用していますか? "_SQL_"はクエリ言語であり、特定のデータベース製品の名前ではありません。 –
どのdbms?間違ったdbmsを解決するのは無駄です。 – Eric