select iName from 表1 where iName in
(select a.iname from 表2 a,表2 b
where a.iname=b.iname and abs(a.iNum-b.iNum)>100 and
b.iDate=(select max(iDate) from 表2 where iDate<a.iDate))
(select a.iname from 表2 a,表2 b
where a.iname=b.iname and abs(a.iNum-b.iNum)>100 and
b.iDate=(select max(iDate) from 表2 where iDate<a.iDate))
解决方案 »
- provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接
- 标识列问题
- 继续提问
- 关于MONEY数据类型字段!
- 【100分】一道SQL面试题,大神求解惑!
- windows XP sp2 环境下同时安装MSSQL Server 2000 和 MSSQL Server 2005
- 纵表变横表
- 如何用SQL2005 配置发送邮件啊! 网上我查看了却大都是SQL2000的,而有一篇是SQL2005的却要谈到outlook的设置,我没有outlook不行吗?
- 请帮我看看这个分布式处理的问题???
- 我的网络是ping得通,连ODBC都连不上!!
- 偶快累死了!这种方法到底好不好? 各位神仙,帮帮偶吧。。。
- 关于vb建立公用模块连接sql数据库的问题
1、最新的月份为当前月份
2、存在某一类只有1个月数据的情况select iName from a where
abs((select Sum(iNum) From
(Select Top 2 iNum From b Where iName=a.iName Order by iDate Desc) as t)
-2*(select Top 1 iNum From b Where iName=a.iName Order by iDate Desc)
)>100
where exists( --要求在表1中存在
select 1 from 表1 where iName=a.iName
)
and exists( --要求与一上月份之差大于100(月份可以不连续)
select 1 from 表2
where iName=a.iName and iDate<a.iDate
and a.iNum-iNum>100)
and iDate=(--要求是当前月份的(最大的一个月)
select max(iDate) from 表2 where iName=a.iName
)
(select a.iname from 表2 a,表2 b
where a.iname=b.iname and a.iNum-b.iNum>100 and
iDate=(select max(iDate) from 表2 where iDate<a.iDate where a.iname=b.iname))
where exists (
(select 1 from 表2 a,表2 b
where a.iname=b.iname and a.iname=x.iname
and a.idate='200406'
and b.iDate=(select max(iDate) from 表2 where iDate<a.iDate)
and a.iNum-b.iNum>100
)
where exists (
(select 1 from 表2 a,表2 b
where a.iname=b.iname and a.iname=x.iname
and a.idate='200406'
and b.iDate=(select max(iDate) from 表2 where iDate<a.iDate and iname=a.iname)
and a.iNum-b.iNum>100
)