SELECT Table_1.F_Text, Sum(Table_1.F_Num) AS SumOfF_Num FROM Table_1 GROUP BY Table_1.F_Text HAVING Sum(Table_1.F_Num)>100;
SQLExecDirect: SELECT "F_Text" ,SUM("F_Num" ) FROM "dbo"."Table_1" GROUP BY "F_Text" HAVING (SUM("F_Num" ) > 100 )期待通りの集計がされて、全レコードを取得するようなことはない。ただし、
クエリ ウィザードで作成したような集計クエリで年月ごとの集計をしようとすると、全レコード取得後、ACEで集計することになる。
SELECT Format([Table_1].[F_Date],'yyyy-mm') AS F_Formated, Sum(Table_1.F_Num) AS SumOfF_Num FROM Table_1 GROUP BY Format([Table_1].[F_Date],'yyyy-mm');
SQLExecDirect: SELECT "F_Num" ,"F_Date" FROM "dbo"."Table_1"なので、
SELECT Year([Table_1].[F_Date]) AS F_Year, Month([Table_1].[F_Date]) AS F_Month, Sum(Table_1.F_Num) AS SumOfF_Num FROM Table_1 GROUP BY Year([Table_1].[F_Date]), Month([Table_1].[F_Date]);
SQLExecDirect: SELECT {fn year("F_Date" )},{fn month("F_Date" )},SUM("F_Num" ) FROM "dbo"."Table_1" GROUP BY {fn year("F_Date" )},{fn month("F_Date" )}という感じにしておけばよいかと。
SELECT [T].[F_Year] & Format([T].[F_Month],'-00') AS F_yyyy_mm, T.SumOfF_Num FROM (SELECT Year([Table_1].[F_Date]) AS F_Year, Month([Table_1].[F_Date]) AS F_Month, Sum(Table_1.F_Num) AS SumOfF_Num FROM Table_1 GROUP BY Year([Table_1].[F_Date]), Month([Table_1].[F_Date])) AS T ORDER BY [T].[F_Year] & Format([T].[F_Month],'-00');こういう書き直しにもなるかな。
クロス集計クエリは、集計クエリの部分が SQL Server 側で処理される感じにすればよい。
0 件のコメント:
コメントを投稿