select count(distinct 用户编号)
from A aa
where 
(
select max(得分)
from a,b
where a.id = b.A表的ID编号
      and  
      a.时间 = (select min(时间) 
                  from b 
                 where 用户编号 = aa.用户编号 
                       and 时间 >= '2004-01-01'
                       and 时间 <= '2004-07-01'                )           
)
>
(
select max(得分)
from a,b
where a.id = b.A表的ID编号
      and  
      a.时间 = (select max(时间) 
                  from b 
                 where 用户编号 = aa.用户编号 
                       and 时间 >= '2004-01-01'
                       and 时间 <= '2004-07-01'
               )           
)

解决方案 »

  1.   

    select t1.用户编号 from @A t1 
    inner join @B t2 
    on t1.ID编号 = t2.A表的ID编号
    inner join @A t3 
    on t3.用户编号 = t1.用户编号
    inner join @B t4
    on t3.ID编号 = t4.A表的ID编号
    where t1.时间 between '2004-01-01' and '2004-07-01' and t3.时间 between '2004-01-01' and '2004-07-01'
    and  t4.得分 > t2.得分 and t3.时间 > t1.时间
      

  2.   

    pignet(猪.net)同志的语句得不到正确结果。
      

  3.   

    playyuer(双规干部) 同志的语句运行有下面的错误提示,能再帮我看看吗?
    An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
      

  4.   

    select distinct t1.用户编号 from @A t1 where 
    (select top 1 B.得分 from @A A inner join @B B on A.ID编号 = B.A表的ID编号 where A.用户编号 = t1.用户编号 order by A.时间 desc ) >
    (select top 1 B.得分 from @A A inner join @B B on A.ID编号 = B.A表的ID编号 where A.用户编号 = t1.用户编号 order by A.时间 )
      

  5.   

    select distinct t1.用户编号 from @A t1 where 
    (select top 1 B.得分 from @A A inner join @B B on A.ID编号 = B.A表的ID编号 where A.用户编号 = t1.用户编号 order by A.时间 desc ) <
    (select top 1 B.得分 from @A A inner join @B B on A.ID编号 = B.A表的ID编号 where A.用户编号 = t1.用户编号 order by A.时间 )
    这是下降