select count(pepole) from table1 a,table1 b
where max(money)<2000 and min(money)>1000
and year='2002'
and a.pepole=b.pepole
where max(money)<2000 and min(money)>1000
and year='2002'
and a.pepole=b.pepole
解决方案 »
- 咨询下表重命名的问题
- 求解sql语句
- Oracle存储过程,在一个for循环里面,要catch到异常,然后continue或者跳出循环怎么做
- 急求 oracle SQL 简化问题!!
- 怎么匹配空行
- jsp 对oracle 表的查询结果无显示
- 人都快崩溃了,请大家帮忙 Oracle - OraClient10g_home2安装后,连接不到服务器
- 如何将ORACLE 数据(WIN2K版)备份到磁带机(急!!1)
- 如何设计这个表能达到最好的效果?
- 我想从数据库中得到在客户端没执行成功的 sql 完整语句,不知有无办法?
- 有关在pro*c中嵌入PL/SQL块的问题
- 如何解决该错误:ORA-06502: PL/SQL: 数字或值错误 :
1月份a用户消费 1500元
2月份a用户消费 200元
3月份a用户消费 1500 元
此种情况不应统计
只有以下情况应统计
1月份a用户消费 1500元
2月份a用户消费 1800元
3月份a用户消费 1500 元
(select pepole,max(cast(money as integer)) m_max
from test
where nf='2002' and cast(yf as integer) between 1 and 3
group by pepole) a,
(select pepole,min(cast(money as integer)) m_min
from test
where nf='2002' and cast(yf as integer) between 1 and 3
group by pepole) b
where a.pepole=b.pepole
and a.m_max<2000 and b.m_min>1000
我在db2环境下写的,通过了测试,你改一下。
cast(money as integer)是把数字转换为integer类型,你可去掉。
--------------------------
NF YF PEPOLE MONEY
---- -- ---------- ----------
2002 1 Wang 1500
2002 2 Wang 1600
2002 3 Wang 1700
2002 1 Li 1700
2002 2 Li 800
2002 3 Li 1200 6 条记录已选择。
--------------------------
楼上结果:
PEPOLE M_MAX M_MIN
---------- ----------- -----------
Wang 1700 1500 1 条记录已选择。