Accessで所望の結果を達成するために、私はアンピボットに最初のテーブルを試してみて、などの各機関の最小値と最大値を得るでしょう:
SELECT A.[Account#], MIN(A.Agency) AS MinAgency, MAX(A.Agency) AS MaxAgency
FROM
(
SELECT B.[Account#], B.Agency1 AS Agency
FROM SourceTable AS B
UNION
SELECT C.[Account#], C.Agency2
FROM SourceTable AS C
UNION
SELECT D.[Account#], D.Agency3
FROM SourceTable AS D
) AS A
GROUP BY A.[Account#]
私は "としてこのクエリを保存するかもしれませんMinMaxAgencyQuery "を作成し、それを使用して"レタータイプ "の列を作成します。
もちろん
SELECT E.[Account#], "Undesignated" AS [Letter Type]
FROM SourceTable AS E LEFT JOIN MinMaxAgencyQuery AS A ON E.[Account#] = A.[Account#]
WHERE MinAgency = "a1" AND MaxAgency = "a1"
UNION
SELECT E.[Account#], "PartiallyDesignated" AS [Letter Type]
FROM SourceTable AS E LEFT JOIN MinMaxAgencyQuery AS A ON E.[Account#] = A.[Account#]
WHERE MinAgency = "a1" AND MaxAgency <> "a1"
UNION
SELECT E.[Account#], "Designated" AS [Letter Type]
FROM SourceTable AS E LEFT JOIN MinMaxAgencyQuery AS A ON E.[Account#] = A.[Account#]
WHERE MinAgency > "a1"
は、このソリューションは、実際に「A1」である「A1」に依存している(したがって、他の機関未満では、文字列を実行するときに次のように はその後、私は、ユニオンクエリで、このコラムを建設します-比較)。私はすべて同じクエリでこれを行うために必要な場合
、私はそうのような3つのUNION句のクエリのそれぞれに私の最初のクエリに置き換えます:
SELECT E.[Account#], "Undesignated" AS [Letter Type]
FROM SourceTable AS E LEFT JOIN (
SELECT A.[Account#], MIN(A.Agency) AS MinAgency, MAX(A.Agency) AS MaxAgency
FROM
(
SELECT B.[Account#], B.Agency1 AS Agency
FROM SourceTable AS B
UNION
SELECT C.[Account#], C.Agency2
FROM SourceTable AS C
UNION
SELECT D.[Account#], D.Agency3
FROM SourceTable AS D
) AS A
GROUP BY A.[Account#]
) AS F ON E.[Account#] = F.[Account#]
WHERE MinAgency = "a1" AND MaxAgency = "a1"
UNION
SELECT E.[Account#], "PartiallyDesignated" AS [Letter Type]
FROM SourceTable AS E LEFT JOIN (
SELECT A.[Account#], MIN(A.Agency) AS MinAgency, MAX(A.Agency) AS MaxAgency
FROM
(
SELECT B.[Account#], B.Agency1 AS Agency
FROM SourceTable AS B
UNION
SELECT C.[Account#], C.Agency2
FROM SourceTable AS C
UNION
SELECT D.[Account#], D.Agency3
FROM SourceTable AS D
) AS A
GROUP BY A.[Account#]
) AS F ON E.[Account#] = F.[Account#]
WHERE MinAgency = "a1" AND MaxAgency <> "a1"
UNION
SELECT E.[Account#], "Designated" AS [Letter Type]
FROM SourceTable AS E LEFT JOIN (
SELECT A.[Account#], MIN(A.Agency) AS MinAgency, MAX(A.Agency) AS MaxAgency
FROM
(
SELECT B.[Account#], B.Agency1 AS Agency
FROM SourceTable AS B
UNION
SELECT C.[Account#], C.Agency2
FROM SourceTable AS C
UNION
SELECT D.[Account#], D.Agency3
FROM SourceTable AS D
) AS A
GROUP BY A.[Account#]
) AS F ON E.[Account#] = F.[Account#]
WHERE MinAgency > "a1"
あなたは口座番号の年代でどうなるか指定したことがないことAgency1、Agency2、およびAgency3の値はありません。したがって、この解決策が与えられても表示されません。
代理店1、代理店2、代理店3は、a(x)値を確認する唯一の3つの列ですか? – Sturgus
お返事いただきありがとうございます。最大20の列があります。実際のテーブル見出しと、使用しているテーブルのサンプルデータの別のイメージを追加しました。 – Don85203
このクエリは作成が非常に困難になることがわかります。これは、データが非常に貧弱にモデル化されているためです。代理店+勘定(+ $指定)が交差テーブル(多数:多く)に配置されていた場合、この問題は軽微です。 DX_Agency列の数の基準は何ですか?あなたはそれがD20_Agencyに行くと言う? – Sturgus