これを解決する方法はよくわかりませんが、基本的には正常に機能しているクエリがあります。私がしていることは、アンケートの質問の結果である 6 つの列を個別にカウントすることです。それから私はそれらを追加します。赤、黄、緑の各結果が機能し、ユーザーが 1 行だけを必要とするため、3 つのグループのカウントを行う必要があります。つまり、赤、琥珀、緑の合計数です。ただし、ユーザーは、サイトごとに同じ情報を返す結果を得たいと考えています。
では、各列またはアンケート カテゴリの数を取得し、それらを合計して、赤、黄色、緑の合計を取得し、これによって各サイトをグループ化する簡単な方法はありますか? SQL は以下にありますが、1 つのサイトに対しては完全に機能します。
Select production_site, SUM(Green.[Bagging]+Green.[Measurable]+
Green.[Appearance]+Green.[Aroma]+Green.[Flavour]+Green.[Texture]) as Target,
SUM(Amber.[Bagging]+Amber.[Measurable]+Amber.[Appearance]+Amber.[Aroma]+
Amber.[Flavour]+Amber.[Texture]) as Action, SUM(Red.[Bagging]+Red.[Measurable]+
Red.[Appearance]+Red.[Aroma]+Red.[Flavour]+Red.[Texture]) as Fail
FROM (SELECT (SELECT COUNT(Grocery_Packaging_And_Coding)
FROM t_Pqe_Grocery
WHERE Grocery_Packaging_And_Coding = 'Target'
AND Production_Site = 'Bradford'
) As Bagging,
(SELECT COUNT(Grocery_Measurable)
FROM t_Pqe_Grocery
WHERE Grocery_Measurable = 'Target'
AND Production_Site = 'Bradford'
) As Measurable,
(SELECT COUNT(Grocery_Appearance)
FROM t_Pqe_Grocery
WHERE Grocery_Appearance = 'Target'
AND Production_Site = 'Bradford'
) As Appearance,
(SELECT COUNT(Grocery_Aroma)
FROM t_Pqe_Grocery
WHERE Grocery_Aroma = 'Target'
AND Production_Site = 'Bradford'
) As Aroma,
(SELECT COUNT(Grocery_Flavour)
FROM t_Pqe_Grocery
WHERE Grocery_Flavour = 'Target'
AND Production_Site = 'Bradford'
) As Flavour,
(SELECT COUNT(Grocery_Texture)
FROM t_Pqe_Grocery
WHERE Grocery_Texture = 'Target'
AND Production_Site = 'Bradford'
) As Texture) AS Green,
(SELECT (SELECT COUNT(Grocery_Packaging_And_Coding)
FROM t_Pqe_Grocery
WHERE Grocery_Packaging_And_Coding = 'Action'
AND Production_Site = 'Bradford'
) As Bagging,
(SELECT COUNT(Grocery_Measurable)
FROM t_Pqe_Grocery
WHERE Grocery_Measurable = 'Action'
AND Production_Site = 'Bradford'
) As Measurable,
(SELECT COUNT(Grocery_Appearance)
FROM t_Pqe_Grocery
WHERE Grocery_Appearance = 'Action'
AND Production_Site = 'Bradford'
) As Appearance,
(SELECT COUNT(Grocery_Aroma)
FROM t_Pqe_Grocery
WHERE Grocery_Aroma = 'Action'
AND Production_Site = 'Bradford'
) As Aroma,
(SELECT COUNT(Grocery_Flavour)
FROM t_Pqe_Grocery
WHERE Grocery_Flavour = 'Action'
AND Production_Site = 'Bradford'
) As Flavour,
(SELECT COUNT(Grocery_Texture)
FROM t_Pqe_Grocery
WHERE Grocery_Texture = 'Action'
AND Production_Site = 'Bradford'
) As Texture) AS Amber,
(SELECT (SELECT COUNT(Grocery_Packaging_And_Coding)
FROM t_Pqe_Grocery
WHERE Grocery_Packaging_And_Coding = 'Fail'
AND Production_Site = 'Bradford'
) As Bagging,
(SELECT COUNT(Grocery_Measurable)
FROM t_Pqe_Grocery
WHERE Grocery_Measurable = 'Fail'
AND Production_Site = 'Bradford'
) As Measurable,
(SELECT COUNT(Grocery_Appearance)
FROM t_Pqe_Grocery
WHERE Grocery_Appearance = 'Fail'
AND Production_Site = 'Bradford'
) As Appearance,
(SELECT COUNT(Grocery_Aroma)
FROM t_Pqe_Grocery
WHERE Grocery_Aroma = 'Fail'
AND Production_Site = 'Bradford'
) As Aroma,
(SELECT COUNT(Grocery_Flavour)
FROM t_Pqe_Grocery
WHERE Grocery_Flavour = 'Fail'
AND Production_Site = 'Bradford'
) As Flavour,
(SELECT COUNT(Grocery_Texture)
FROM t_Pqe_Grocery
WHERE Grocery_Texture = 'Fail'
AND Production_Site = 'Bradford'
) As Texture) AS Red,
t_Pqe_Grocery
Where Production_Site = 'Bradford'
Group By production_site