如何匹配两个表列数据并计算第一个表的不匹配行

时间:2011-04-25 18:06:03

标签: sql-server

Tbl_cdr(ano,starttime)
Tbl_User(id,mobileno)

我想计算来自Tbl_cdr的行,条件是省略行(ano = mobileno时)和starttime分组。

任何帮助,Plz ......

2 个答案:

答案 0 :(得分:3)

select c.starttime, count(*)
from Tbl_cdr c
where not exists (select 1 from Tbl_User u where u.mobileno = c.ano)
group by c.starttime

答案 1 :(得分:2)

select count(*), c.StartTime
  from Tbl_cdr     c
left join Tbl_User u  on c.ano = u.mobileno
where u.id is null
group by c.StartTime