0

ステップ 1t1 - where field1is present (つまり、null ではない)のすべての行をカウントし、Count1年と月でグループ化します。

SELECT
  Year(t1.date) AS Year,
  Month(t1.date) AS Month,
  Count(t1.field1) As Count1,
FROM t1
GROUP BY Year(t1.date), Month(t1.date)

ステップ 2t1 -の値t1.field1NOT IN t2.field1であるすべての行を数え、Count2年と月でグループ化します。

SELECT
  Year(t1.date),
  Month(t1.date),
  Count(*) t1.field1 AS Count2,
  FROM t1 LEFT JOIN t2 ON t1.field1 = t2.field1
  WHERE ISNULL t2.field1
GROUP BY Year(t1.date), Month(t2.date)

ステップ 3 - 上記の両方のカウントの結果をYear(t1.date)行ヘッダーと列ヘッダーとして表に表示し、各月の下に とMonth(t1.date)の結果をCount1ネストCount2します。

方法がわからないため、手順 3 で表示するコードはありません。

4

1 に答える 1

0

これを試して。

SELECT
      STEP1.Total_Rows_S1, STEP1.Year_S1, STEP1.Month_S1, COUNT(*) as Remaining_Rows
FROM (
            SELECT
            Year(t1.date) AS Year_S1,
            Month(t1.date) AS Month_S1,
            Count(t1.field1) As Total_Rows_S1,
            t1 .field1 AS FS1
            FROM t1
            GROUP BY Year(t1.date), Month(t1.date)
) AS STEP1 LEFT JOIN t2 ON (STEP1.FS1 = t2.field1)
WHERE ISNULL t2.field1
GROUP BY STEP1.Year_S1, Month( t2.date)

于 2012-12-30T05:20:55.733 に答える