日期:2014-05-18 浏览次数:20679 次
select distinct productID as PID,count(*) as times -- into #temp from pordersub inner join porder on pordersub.porderID = porder.porderID where datediff(month,porder.updatetime,getdate()) =0 group by productID
select distinct productID as PID,case when count(1) > 1 then 1 else 0 end as isporder -- into #temp from pordersub inner join porder on pordersub.porderID = porder.porderID where datediff(month,porder.updatetime,getdate()) =0 group by productID
------解决方案--------------------
update p set isporder=case when times>1 then 'true' else 'false' end
from product p,
(
select distinct productID as PID,count(*) as times -- into #temp
from pordersub inner join porder
on pordersub.porderID = porder.porderID where datediff(month,porder.updatetime,getdate()) =0 group by productID
) t
where t.productID =p.productID