RepId とその日付で構成されるテーブルがあります。
Table: 1
RepID Date
108981 2013-04-09 00:00:00.000
108981 2013-04-09 00:00:00.000
108982 2013-04-10 00:00:00.000
108982 2013-04-11 00:00:00.000
108983 2013-04-11 00:00:00.000
108983 2013-04-11 00:00:00.000
RepId とその logTime で構成される別のテーブルがあります。
Table: 2
repID logTime
108981 2013-04-09 00:00:00.000
108981 2013-04-09 00:00:00.000
108982 2013-04-11 00:00:00.000
108983 2013-04-11 00:00:00.000
108983 2013-04-11 00:00:00.000
108984 2013-04-10 00:00:00.000
表 2 の担当者の logtime が存在しない場合、表 1 の RepId の数が必要です。
この場合、出力が必要です
repId RepCount
108982 1
日付「2013-04-10 00:00:00.000」は、RepId - 108982 のテーブル 2 に存在しないためです。
クエリを次のように使用しました
select
t1.RepID, count(t1.RepID) as 'Rep Count'
from
table1 t1
where
not exists
(select t2.repID from table2 t2 where
CONVERT(date, t2.logTime) between '2013-04-08 00:00:00.000' and '2013-04-11 00:00:00.000')
group by
t1.RepID
しかし、それは常に何も返しません。この問題から抜け出すために助けてください....