我写的SQL语句如下:
SELECT *
FROM vipPlan LEFT OUTER JOIN
(select top 1 ID,FanganNumber from VipProgress where fangannumber=vipPlan.FanganNumber ) as cc on cc.fangannumber = vipPlan.FanganNumber
报错内容如下:
消息 4104,级别 16,状态 1,第 1 行
无法绑定由多个部分组成的标识符 "vipPlan.FanganNumber"。
------解决方案--------------------
- SQL code
declare @VipPlan table (ID int,fanganhao int)insert into @VipPlanselect 1,111 union allselect 2,222declare @VipProgress table (ID int,fanganhao int,[datetime] datetime,weight int)insert into @VipProgressselect 1,111,'2012-2-1',50 union allselect 2,222,'2012-2-1',51 union allselect 3,111,'2012-2-4',50 union allselect 4,111,'2012-2-2',53select b.id as bid,b.fanganhao as afanganhao,a.id as aid,a.[datetime],a.weight from @vipplan bleft join @vipprogress aon a.fanganhao=b.fanganhaowhere [datetime]=(select max([datetime]) from @vipprogress where fanganhao=a.fanganhao)/*bid afanganhao aid datetime weight----------- ----------- ----------- ----------------------- -----------2 222 2 2012-02-01 00:00:00.000 511 111 3 2012-02-04 00:00:00.000 50*/