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'
)
)
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'
)
)
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.时间
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.
(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.时间 )
(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.时间 )
这是下降