---
Declare @SID1 int
Declare @SID2 int
--@SID1=38
select top 1 @SID1=SID from (select top 60 SID from Equipment group by SID order by SID ) A order by SID desc
--Count(SenInID)=133
select count(SenInID) from Equipment where SID<=@SID1 --用下列语句查询错误??
select count(*) from Equipment where 
SID<=(select top (1) SID from 
(select top (30) SID from Equipment group by SID order by SID) as a order by SID desc)如何将SQL语句合并成一条SQL语句?

解决方案 »

  1.   


    select count(*) from Equipment where 
    SID<=(select top (1) SID from 
    (select top (30) SID from Equipment group by SID order by SID) as a order by SID desc)查询语句错误???
      

  2.   

    select count(*) from Equipment where 
    SID<=
    (select top 1 SID from 
    (select top 30 SID from Equipment group by SID order by SID) as a 
    order by SID desc)
      

  3.   


    select count(*) from Equipment where 
    SID<=(select top (1) SID from 
    (select top (30) SID from Equipment group by SID order by SID) as a order by SID desc)服务器: 消息 170,级别 15,状态 1,行 2
    第 2 行: '(' 附近有语法错误。
    服务器: 消息 170,级别 15,状态 1,行 3
    第 3 行: '(' 附近有语法错误。
      

  4.   


    top (1)改为 top 1  top (30)改为 top 30 或者用前面写给你的句子都行,一样的
      

  5.   

    你这是否2000?
    换成这样
    select count(*) from Equipment where 
    SID<=(select top 1 SID from 
    (select top 30 SID from Equipment group by SID order by SID) as a order by SID desc)