select top 1 a.id,b.id 
from Company as a inner join Accountable as b 
on a.id=b.CompanyID and b.Authentication=2 
where a.id <(select min(a.id) --这里为什么不能用a.id 啊。
from 
(select top 2 a.id 
from Company as a inner join Accountable as b 
on a.id=b.CompanyID and b.Authentication=2 
order by a.id desc) as tblTmp)
 
order by a.id desc解决一下啊

解决方案 »

  1.   

    不能用a就直接用Accountable不就行了?
      

  2.   

    消息 4104,级别 16,状态 1,第 18 行
    无法绑定由多个部分组成的标识符 "Authentication.id"。
      

  3.   

     因为 表A 已经与表Bjoin了 他不再是属于一个单纯的A表 所以你要得到表a的id
     那么就要  
    select top 1 a.id,b.id from (
    select * 
    from Company as a inner join Accountable as b 
    on a.id=b.CompanyID and b.Authentication=2 ) d然后用 d.id 就行了...
      

  4.   


    select top  5 a.id,b.id 
    from Company as a,Accountable as b  
    where a.id <(select min(a.id)--还是一样啊 
    from (select top  5 a.id 
    from Company as a,Accountable as b  
    where  a.id=b.CompanyID and b.Authentication=2  
    order by a.id desc) as tblTmp) and  a.id=b.CompanyID and b.Authentication=2  
    order by a.id desc。
      

  5.   

    select top 1 a.id,b.id 
    from Company as a inner join Accountable as b 
    on a.id=b.CompanyID and b.Authentication=2 
    where a.id <(select min(tblTmp.id) --注意:from里面的表名此时是tblTmp
    from 
    (select top 2 a.id as id  --这里加个列名
    from Company as a inner join Accountable as b 
    on a.id=b.CompanyID and b.Authentication=2 
    order by a.id desc) as tblTmp)
     
    order by a.id desc
      

  6.   


    select top 1 a.id,b.id 
    from Company as a inner join Accountable as b 
    on a.id=b.CompanyID and b.Authentication=2 
    where a.id <(select min(Company.id) --这里为什么不能用a.id 啊。
    from 
    (select top 2 Company.id 
    from Company inner join Accountable
    on Company.id=Accountable.CompanyID and Accountable.Authentication=2 
    order by Company.id desc) as tblTmp)
     
    order by a.id desc
      

  7.   

    消息 4104,级别 16,状态 1,第 1 行
    无法绑定由多个部分组成的标识符 "Company.id"。
      

  8.   


    select min(a.id) --这里为什么不能用a.id 啊。
    from 
    (select top 2 a.id 
    from Company as a inner join Accountable as b 
    on a.id=b.CompanyID and b.Authentication=2 
    order by a.id desc) as tblTmp) a
    这样可以吧。因为你查询的是(select top 2 a.id 
    from Company as a inner join Accountable as b 
    on a.id=b.CompanyID and b.Authentication=2 
    order by a.id desc) as tblTmp)这个作为一个整体看。