急,如何一下子统计出表中每个字段大于30000值 的记录数(125分)

W

wukw

Unregistered / Unconfirmed
GUEST, unregistred user!
比方:table1 中 column1>30000 的共有 1000条记录(1)
column2>30000 的共有 2000条记录(2)
如果某一条记录 column1>30000, column2>30000 ,那么 这一条记录将被 分别记录 (1)和(2),即可以重复计算。

请指教!多谢了!!

 
没有什么好的办法。
num(column1>30000) + num(column2>30000) - num(column1>30000 and column2>30000)
最好只有两个字段啦,字段多,这种方法受不了。
 
重复计算是什么意思?
 
select count(*) from tablename
where column>30000
 
我用Oracle,我的意思就是说:
select count(*) from tablename
where column>30000
这样要一个一个写字段名称,有没有办法一起显示出来。

请您参考一下这个:(自动找出所有字段)
00:09:37 SQL> select 'alter table tmp modify ('||COLUMN_NAME||' not null);'
OK:
00:09:44 2 from user_tab_columns where TABLE_NAME = 'TMP';

'ALTERTABLETMPMODIFY('||COLUMN_NAME||'NOTNULL);'
------------------------------------------------------------------
alter table tmp modify (DS not null);
alter table tmp modify (PARENTITEM not null);
alter table tmp modify (CURRENTITEM not null);
alter table tmp modify (TNAME not null);

已用时间: 00: 00: 00.20
 
估计只好用procedure来解决问题啦!
不管如何,你要将查询出来的所有字段名在你的应用中由纵向转为横向,一句话看来是
无法达到你的要求。
 
可以写procedure,也可以在客户端一次一次的查,没有好办法
 
用存储过程
 
SELECT COM_NAME='COM1',VCOUNT=COUNT(*)
FROM TABLE
WHERE COM1>5000

UNION

SELECT COM_NAME='COM2',VCOUNT=COUNT(*)
FROM TABLE
WHERE COM2>5000
 
select
sum((column1>30000)+(column2>30000)) from table
 
多人接受答案了。
 
顶部