给一个大概的伪代码,这个应该放到数据库版去问。select x.人名, x.缴费日期 from Table1 x Where Exists(select 1 from Table1 t, where t.人名=x.人名 and t.缴费日期>x.缴费日期) and not exists(select 1 from Table1 t, where t.人名=x.人名 and t.缴费日期>x.缴费日期 and t.缴费日期-x.缴费日期<=3年)
好像写的不对吧,怎么两个表别名为T select x.hyid, x.jfsj from Tjiaofei x Where Exists(select 1 from Tjiaofei t where t.hyid=x.hyid and t.jfsj>x.jfsj) and not exists(select 1 from Tjiaofei t where t.hyid=x.hyid and t.jfsj>x.jfsj and t.jfsj-x.jfsj<=1)
因为这2个别名t的作用域没有重叠,都在各自的括号里,至少Oracle是可以的。
此事,关系数据库表的字段设计: 1、加入字段“缴费年月”,存入值为‘2014-01’,‘2013-12’..... 2、加入字段“缴费日期”,存入值为‘2014-01-01’,‘2014-01-02’..... 3、查询时 (1)连续三天 缴费数据 SQL:='select * from 表名 where 缴费日期>=''2014-01-01'' and 缴费日期<=''2014-01-03''' (2)三年未缴费 需要编写一个函数,批出三年示缴费人的名单。再该人加入SQL中。
Where
Exists(select 1 from Table1 t, where t.人名=x.人名 and t.缴费日期>x.缴费日期)
and not exists(select 1 from Table1 t, where t.人名=x.人名 and t.缴费日期>x.缴费日期 and t.缴费日期-x.缴费日期<=3年)
这样的技巧常常用在exists之类的语句中,作用是减少返回字段的内容。不知道sqlite是不是支持这样的查询语句,如果不支持的话,可以随便拉一个存在的字段来替代这个1.
select x.hyid, x.jfsj from Tjiaofei x
Where
Exists(select 1 from Tjiaofei t where t.hyid=x.hyid and t.jfsj>x.jfsj)
and not exists(select 1 from Tjiaofei t where t.hyid=x.hyid and t.jfsj>x.jfsj and t.jfsj-x.jfsj<=1)
1、加入字段“缴费年月”,存入值为‘2014-01’,‘2013-12’.....
2、加入字段“缴费日期”,存入值为‘2014-01-01’,‘2014-01-02’.....
3、查询时
(1)连续三天 缴费数据
SQL:='select * from 表名 where 缴费日期>=''2014-01-01'' and 缴费日期<=''2014-01-03'''
(2)三年未缴费
需要编写一个函数,批出三年示缴费人的名单。再该人加入SQL中。