1つの例外を除いて、次のクエリでは、ご希望の結果を提供します。ただし、Total_Discount
とTotal_Motivation
の列は通貨としてフォーマットされていません(フォーマットされた列は数値ではなく文字列になるため、望ましくない場合があります)。
SELECT t.The_Year
, t.The_Month
, t.Emp_Num
, Nz(DSum("Money_Amount","Table1","Discount_Motivation = 'Discount' AND The_Year = " & t.The_Year & " AND The_Month = " & t.The_Month & " AND Emp_Num = " & t.Emp_Num), 0) AS Total_Discount
, ConcatRelated("Reason","Table1","Discount_Motivation = 'Discount' AND The_Year = " & t.The_Year & " AND The_Month = " & t.The_Month & " AND Emp_Num = " & t.Emp_Num) AS Discount_Reasons
, Nz(DSum("Money_Amount","Table1","Discount_Motivation = 'Motivation' AND The_Year = " & t.The_Year & " AND The_Month = " & t.The_Month & " AND Emp_Num = " & t.Emp_Num), 0) AS Total_Motivation
, ConcatRelated("Reason","Table1","Discount_Motivation = 'Motivation' AND The_Year = " & t.The_Year & " AND The_Month = " & t.The_Month & " AND Emp_Num = " & t.Emp_Num) AS Motivation_Reasons
FROM Table1 t
GROUP BY t.The_Year, t.Emp_Num, t.The_Month
ORDER BY t.The_Year, t.Emp_Num, t.The_Month
;
、このようなフォーマットは、本当に必要な場合しかし、あなたは単にFormat
機能でこれらの列の行をラップし、2番目の引数として「通貨」を提供することで、そうすることができます。
SELECT t.The_Year
, t.The_Month
, t.Emp_Num
, Format(Nz(DSum("Money_Amount","Table1","Discount_Motivation = 'Discount' AND The_Year = " & t.The_Year & " AND The_Month = " & t.The_Month & " AND Emp_Num = " & t.Emp_Num), 0), "Currency") AS Total_Discount
, ConcatRelated("Reason","Table1","Discount_Motivation = 'Discount' AND The_Year = " & t.The_Year & " AND The_Month = " & t.The_Month & " AND Emp_Num = " & t.Emp_Num) AS Discount_Reasons
, Format(Nz(DSum("Money_Amount","Table1","Discount_Motivation = 'Motivation' AND The_Year = " & t.The_Year & " AND The_Month = " & t.The_Month & " AND Emp_Num = " & t.Emp_Num), 0), "Currency") AS Total_Motivation
, ConcatRelated("Reason","Table1","Discount_Motivation = 'Motivation' AND The_Year = " & t.The_Year & " AND The_Month = " & t.The_Month & " AND Emp_Num = " & t.Emp_Num) AS Motivation_Reasons
FROM Table1 t
GROUP BY t.The_Year, t.Emp_Num, t.The_Month
ORDER BY t.The_Year, t.Emp_Num, t.The_Month
;
こちらをご覧ます。http:// STAC koverflow.com/questions/19478272/converting-mysql-code-to-access-group-concat-and-a-triple-join –