日期:2014-05-18 浏览次数:20602 次
select count( distinct imsi) from( select *,rank() over (partition by Imsi order by MTime desc) idx from OutDesc7Day_20120117 with(nolock) where MTime<'2012-01-17 13:00' )t left join TourProvinceCity c on convert(varchar(20),t .VlrNum) = c.VlrNum where idx=1 and left( convert(varchar(20),t.VlrNum),5) in('19861') select count( distinct imsi) from( select *,rank() over (partition by Imsi order by MTime desc) idx from OutDesc7Day_20120117 with(nolock) where MTime<'2012-01-17 13:00' )t left join TourProvinceCity c on convert(varchar(20),t .VlrNum) = c.VlrNum where idx=1 and City<>'广州' and left( convert(varchar(20),t.VlrNum),5) in('19861') select count( distinct imsi) from( select *,rank() over (partition by Imsi order by MTime desc) idx from OutDesc7Day_20120117 with(nolock) where MTime<'2012-01-17 13:00' )t left join TourProvinceCity c on convert(varchar(20),t .VlrNum) = c.VlrNum where idx=1 and City='广州' and left( convert(varchar(20),t.VlrNum),5) in('19861')
where City is not null --可以把null的都去掉再比较