有一个表n06,
里面有数据
n0601 n0602
331 23
331 -23
331 45
331 -26
331 -45现在如何查询可以把n0602数据相加为0的去掉,只得到-26这个数据 select * from n06该怎么写语句
里面有数据
n0601 n0602
331 23
331 -23
331 45
331 -26
331 -45现在如何查询可以把n0602数据相加为0的去掉,只得到-26这个数据 select * from n06该怎么写语句
解决方案 »
- 64 位 windows server 2008 上需要安装什么才能使 ASP 连接上 Orcale 数据库服务器
- oracle可以看数据库里的表么??
- 请问用imp 导入 带嵌套表的数据表具体应该做?
- 请教sqlserver2000的备份数据库文件如何导入到oracle
- ORACLE数据库越来越大的问题
- 数据表中存放对员工的打分情况,想统计各员工的平均分值。请问该SQL语句如何写?
- 求助2个问题
- DATE问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- oracle的update语句有毛病???请问如何解决这个update语句??
- oracle中如何通过表中的字段内容检索表名
- Oracle10g 不能安装在RHEL AS4里面。提示只能为AS2、AS3。。。
- jdbc读表数据
(select abs(n0602) from n06 group by abs(n0602) having count(1) > 1);
---------- ----------
331 23
331 -23
331 45
331 -26
331 -45已用时间: 00: 00: 00.01
12:47:41 scott@TUNGKONG> select * from n06 where abs(n0602) not in
12:47:44 2 (select abs(n0602) from n06 group by abs(n0602) having count(1) > 1);N0601 N0602
---------- ----------
331 -26已用时间: 00: 00: 00.00
(
select 331 n0601,23 n0602 from dual
union all
select 331 ,-23 from dual
union all
select 331 ,45 from dual
union all
select 331 ,-29 from dual
union all
select 331 ,-28 from dual
union all
select 331 ,-45 from dual)
select* from (
select n0601,sum(n0602) as n0602
from t
group by n0601,abs(n0602)
)
where n0602<>0
这样就可以了
from n06 t1
where exists (select 1 from n06 t2 where t2.n0602 = - t1.n0602);
select *
from n06 t1
where not exists (select 1 from n06 t2 where t2.n0602 = - t1.n0602);
那位朋友只是做个实例而已
所以就只列了6条数据下面跟着的那个SQL语句在楼主那里应该也是可以的
select n0601,sum(n0602) as n0602
from t
group by n0601,abs(n0602)
)
where n0602<>0这个试试
select '331' no601,23 no602 from dual
union all
select '331' no601,-23 no602 from dual
union all
select '331' no601,45 no602 from dual
union all
select '331' no601,-26 no602 from dual
union all
select '331' no601,-45 no602 from dual
)
select no601,sum(no602) from temp group by no601 having sum(no602) <> 0结果:
1 331 -26
select '331' no601,26 no602 from dual
union all
select '331' no601,-26 no602 from dual
union all
select '331' no601,26 no602 from dual
union all
select '331' no601,-25 no602 from dual
union all
select '331' no601,-24 no602 from dual
)
select no601,sum(no602) from temp group by no601 having sum(no602) <> 0这样的结果是:-23
select '331' no601,26 no602 from dual
union all
select '331' no601,26 no602 from dual
union all
select '331' no601,-24 no602 from dual
union all
select '331' no601,-26 no602 from dual
union all
select '331' no601,-25 no602 from dual
)
select no601,sum(no602) from temp group by no601 having sum(no602) <> 0
select a,sum(b) as n0602
from sum_zero
group by a,abs(b)
)
where n0602<>0