1

2 つの列を持つテーブルがあります。1 つは日時列 (Test_Complete) で、もう 1 つは英数字のレコード ID 列 (RecordID) です。

月単位で処理されたレコード ID の数を準備する必要があります。そのためのクエリをすでに作成しています。

SELECT (Format([Test_Complete],"mmm"" '""yy")) AS Evaluation_Month, 
Count(tbl_TestStatus.Record_ID) AS CountOfRecord_ID
FROM tbl_TestStatus
WHERE (((tbl_TestStatus.[Test_Complete]) Is Not Null))
GROUP BY (Format([Test_Complete],"mmm"" '""yy")),
(Year([Test_Complete])*12+Month([Test_Complete])-1);

このクエリはうまく機能し、次のような出力が得られます。

Evaluation_Month     CountOfRecord_ID
------------------   -----------------
 Jan'12                   20
 Feb'12                   90
 Mar'12                   40
 Apr'12                   50

ここで必要なのは、各 Evaluation_Month に対する CountOfRecord_ID 値のパーセンテージを計算し、そのパーセンテージを Eva​​luation_Month データの値に追加することです。

上記の結果セットでは、すべての CountOfRecord_ID の合計は 200 です。そのため、200 を 100% としてパーセンテージを計算する必要があります。結果は次のようになります。

Evaluation_Month     CountOfRecord_ID
------------------   -----------------
 Jan'12 (10%)                20
 Feb'12 (45%)                90
 Mar'12 (20%)                40
 Apr'12 (25%)                50

これを実現するために SQL クエリを変更するにはどうすればよいですか?

4

1 に答える 1

3

selectレコードの総数を含むステートメントに「サブクエリ フィールド」を追加するだけです。このようなもの:

SELECT 
    (Format([Test_Complete],"mmm"" '""yy")) AS Evaluation_Month, 
    Count(tbl_TestStatus.Record_ID) AS CountOfRecord_ID,
    Count(tbl_TestStatus.Record_ID) / (select count(tbl_testStatus.recordId
     from tbl_testStatus
     where tbl_testStatus.test_complete is not null) as percent
FROM 
    tbl_TestStatus
WHERE 
    (((tbl_TestStatus.[Test_Complete]) Is Not Null))
GROUP BY 
    (Format([Test_Complete],"mmm"" '""yy")),
    (Year([Test_Complete])*12+Month([Test_Complete])-1);
于 2013-02-28T06:14:16.487 に答える