日期:2014-05-17  浏览次数:20751 次

请教一个sql的问题
我表A中有3列
a(金额)           ,b(编号)           ,c(用户编号),t(时间)

表B中有3列
c(用户编号)         d(用户名)         e(密码)
我想得到
在某个时间段内,对于交易金额大于某一个常数   比如说2000的用户在该时间段内的每一条交易记录
请问这个语句怎么写?

------解决方案--------------------
select a.a,a.b,a.c,a.t,b.d
from A a,
B b
where a.c=b.c
and a.c in (select c from a where t between t1 and t2 group by c having sum(a) > 2000)
------解决方案--------------------
select a,b,A.c,t,d from A ,b
where A.c =B.c
and t between StartTime and EndTime
and c in
(
select c from A where t between StartTime and EndTime
group by c
having sum(a)> 某个常数
)
order by A.c, t
;

------解决方案--------------------
select a.a,a.b,a.c,a.t,b.d
from A a,
B b
where a.c=b.c
and a.t between t1 and t2
and a.c in (select c from a where t between t1 and t2 group by c having sum(a) > 2000)

忘加时间了
------解决方案--------------------
select a,b,A.c,t,d from A ,b
where A.c =B.c
and
(
select a1.c, sum(a1.a) from A a1 where a1.t between StartTime and EndTime and
a1.c = a.a
group by a1.c
having sum(a1.a)> 2000)