私は数日間これと戦ってきました。私はSQLの専門家ではなく、いくつかのクエリを作成することができましたが、クエリをまとめるという実際の仕事があります。SQL結合の問題 - 2つの関連するクエリを結合する(完全外部結合)
例えば、私は次の2つのクエリに参加したい:
SELECT publication_id AS Pure_Publication_Id, caa.person_id,
caa.name_first_name AS Primary_Author_First_Name,
caa.name_last_name AS Primary_Author_Last_Name
FROM pure.classified_author_assoc caa
LEFT OUTER JOIN Pure.Publication
ON Caa.Publication_Id = Publication.Id
WHERE Caa.Person_Id IS NOT NULL
AND publication.id IN
(
SELECT DISTINCT pure.publication_project_assoc.publication_id
FROM Pure.project
JOIN Pure.Publication_project_assoc
ON project.id = Pure.Publication_project_assoc.project_id
WHERE pure.project.source_id IN ('XEP378', 'XES049', 'YAH001')
)
GROUP BY publication_id, caa.person_id, caa.name_first_name, caa.name_last_name;
と
SELECT publication.id AS Pure_Publication_Id
COUNT (person_id) AS "NUMBER_OF_AUTHORS",
CASE WHEN COUNT (person_id) > 1 THEN 'Yes'
else 'No' END AS Additional_Authors
FROM pure.classified_author_assoc caa
LEFT OUTER JOIN Pure.Publication
ON Caa.Publication_Id = Publication.Id
WHERE Caa.Person_Id IS NOT NULL
AND publication.id IN
(
SELECT DISTINCT pure.publication_project_assoc.publication_id
FROM Pure.project
JOIN Pure.Publication_project_assoc
ON project.id = Pure.Publication_project_assoc.project_id
WHERE pure.project.source_id IN ('XEP378', 'XES049', 'YAH001')
)
GROUP BY publication.id;
を、私は単一のクエリでそれらを組み合わせることはできません(私は考えていない)最初のクエリとしてNumber_of_authorsを1として返すだけです。しかし、私がクエリを実行しようとすると、真ん中で完全に次のように結合されますが、SQLコマンドが最初のSQL文の最後に正しく終了しないというエラーが発生します。終わり。
SELECT publication_id AS Pure_Publication_Id, caa.person_id,
caa.name_first_name AS Primary_Author_First_Name,
caa.name_last_name AS Primary_Author_Last_Name
FROM pure.classified_author_assoc caa
LEFT OUTER JOIN Pure.Publication
ON Caa.Publication_Id = Publication.Id
WHERE Caa.Person_Id IS NOT NULL
AND publication.id IN
(
SELECT DISTINCT pure.publication_project_assoc.publication_id
FROM Pure.project
JOIN Pure.Publication_project_assoc
ON project.id = Pure.Publication_project_assoc.project_id
WHERE pure.project.source_id IN ('XEP378', 'XES049', 'YAH001')
)
GROUP BY publication_id, caa.person_id, caa.name_first_name, caa.name_last_name
FULL OUTER JOIN
(
SELECT publication.id AS Pure_Publication_Id,
COUNT (person_id) AS "NUMBER_OF_AUTHORS",
CASE WHEN COUNT (person_id) > 1 THEN 'Yes'
else 'No' END AS Additional_Authors
FROM pure.classified_author_assoc caa
LEFT OUTER JOIN Pure.Publication
ON Caa.Publication_Id = Publication.Id
WHERE Caa.Person_Id IS NOT NULL
AND publication.id IN
(
SELECT DISTINCT pure.publication_project_assoc.publication_id
FROM Pure.project
JOIN Pure.Publication_project_assoc
ON project.id = Pure.Publication_project_assoc.project_id
WHERE pure.project.source_id IN ('XEP378', 'XES049', 'YAH001')
)
)
GROUP BY publication.id
ON ****;
私はこれをあらゆる方法で試してみて、それが何か簡単なものでなければならないことを知っています。誰でも助けてくれますか?
複雑でないサンプルでこの問題を説明することはできますか? – hkutluay