表1结构
field1 field2 field3
日期型 数值型 外部主键
表2结构
field3
主键
求:1.表1中所有两个日期之间(avg(field2)/月)<固定值的所有记录
2.表一中所有两个日期之间无记录的所有记录
field1 field2 field3
日期型 数值型 外部主键
表2结构
field3
主键
求:1.表1中所有两个日期之间(avg(field2)/月)<固定值的所有记录
2.表一中所有两个日期之间无记录的所有记录
解决方案 »
- 怎样判断数据是否是boolean类型
- 一个SPEEDBUTTON可以在多个EDIT中输入,而且光标会随着输入而跳到输入值后面一位?
- 请举例说明一下过程str的用法! 谢谢!
- 是怎么一回事,我想实现这样的功能不知道可不可以阿?
- 求助:如何判断tdbgrid中所有行某列中的数值的正负?
- 为什么我的DELPHI6不能输入汉字?
- 关于canvas does not allow drawing 错误的成因
- 各位大虾:为什么不能在Database Desktop中编辑DB表中的Memo字段?谢谢!
- 谁能帮我解释一下。内存映射文件到底是什么东东呢?
- 我怎么才能把delphi专题下的所有文章下载到本地
- 编辑ListView的问题
- 为什么前面的procedure无法调用后面的procedure?
表1:缴费日期 缴费金额 用户ID
2002-01-08 50 1
2002-01-10 100 1
2002-01-08 50 2
2002-01-10 100 2
2002-02-08 50 1
2002-02-10 100 1
2002-03-08 50 1
2002-03-10 100 1
2002-04-08 50 1
2002-04-10 100 1
2002-04-08 50 2
2002-04-10 100 2
表2:
用户ID
1
2
求:1.2002年1月--5月平均交费<30元的所有用户
2.2002年1月--5月有连续2个月未交费的用户
1、select * from 表2 where 用户ID in (select 用户ID from (select 用户ID,avg(缴费金额) from 表1 where 缴费日期>'2002-01-00' and 缴费日期<'2002-06' goup by 用户ID having avg(缴费金额)<30) as a)
2、select substring(缴费日期,1,7),用户ID from 表1 where group by substring(缴费日期,1,7),用户ID
------------
我表达的可能不清楚
应该是月平均交费额而你的是平均交费额
SELECT id
FROM TABLE1
GROUP BY id
HAVING (SUM(data) > 30 * DATEDIFF(mm, MIN([date]), MAX([date])) + 30)2.
FROM TABLE1
WHERE (3 NOT IN
(SELECT month
FROM (SELECT MONTH([date]) AS [month], id
FROM TABLE1
GROUP BY id, [date]) b
WHERE b.id = table1.id))
GROUP BY id
这个可以判断是否缴纳了3月份的数据。
如果判断两个月的,多增加where部分的判断吧.and 4 not in or 4not in and 5 not in...
我也不知道有没有什么简单的办法。呵呵找找看先,有点变态
from table2
where u_id in (
select u_id
from table1
where 缴费日期 between '2002-01-01' and '2002-05-31'
group by u_id,datepart(mm,缴费日期)
having avg(缴费金额)>30
)
CREATE PROCEDURE test1 @begin_date char(10), @end_date char(10),@money money AS
create table #temp1(a char(10),b money ,c int )
insert #temp1
select c,sum(b),count(substring(a,1,7))
from a
where substring(a,1,7)>=@begin_date and substring(a,1,7)<=@end_date
group by c
select *
from #temp1
where b/c<=@money
drop table #temp1
GO
exec test1 '2005-01-01','2007-01-01',60
CREATE PROCEDURE test1 @begin_date char(10), @end_date char(10),@money money AS
create table #temp1(a char(10),b money ,c int )
insert #temp1
select aa,sum(bb),count(substring(aa,1,7))
from a
where aa>=@begin_date and aa<=@end_date
group by aa select *
from #temp1
where b/c<=@money drop table #temp1
GO
exec test1 '2005-01-01','2007-01-01',100
1、select * from 表2 where 用户ID in (select 用户ID from (select 用户ID,substring(缴费日期,1,7),avg(缴费金额) from 表1 where 缴费日期>'2002-01-00' and 缴费日期<'2002-06' goup by 用户ID,substring(缴费日期,1,7) having avg(缴费金额)<30) as a)