sql 临时空间 连接 分组

with temp_data as(select shareID,carID from dbo.che_ShareCar) 
select car_info.CARID, car_info.CAR_MARK , case when min(shareID) is null then 0 else COUNT(CAR_INFO.CARID) end as sharecount
from dbo.CAR_INFO left join temp_data on CAR_INFO.CARID=temp_data.carID
where COMPANYID=2 --and shareID is not null
group by CAR_INFO.CARID,CAR_INFO.CAR_MARK
posted @ 2011-08-02 17:02  Devin Mao  阅读(200)  评论(0编辑  收藏  举报