首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

请问在一条SQL中求三种条件的和

2012-03-25 
请教在一条SQL中求三种条件的和请问如何可以一条SQL,求三种条件的和。比如stutas分别为50,40,30,的记录数总

请教在一条SQL中求三种条件的和
请问如何可以一条SQL,求三种条件的和。
比如stutas分别为50,40,30,的记录数总和

现在只能分别用3条SQL语句求出,请问有没有可能在一条SQL中求出,并且分别显示出来。

[解决办法]
select status,count(*) from t where status in (50,40,30) group by status;
[解决办法]
select sum(decode(status,30,1,0)) count1,sum(decode(status,40,1,0)) count2,
sum(decode(status,50,1,0)) count3
from table
[解决办法]
select status,
sum(quantity)
from tablename
where status in (50,40,30)
group by status;

[解决办法]
up
[解决办法]
select sum(c) status,c from table1 where c in(50,30,40) group by c;


[解决办法]
select status,
sum(quantity)
from tablename
where status in (50,40,30)
group by status;

这句对 或者用苯办法 
select
sum(quantity)
from tablename
 where status= '50 ' or status= '40 ' or status= '30 ';
[解决办法]
正解
[解决办法]
select sum(1) as bb into #c
from table
where status in (1200,2000,6000)
group by status

select sum(bb) from #c

drop table #c
[解决办法]
select sum(1) as bb into #c
from table
where status in (50,30,40)
group by status

select sum(bb) from #c

drop table #c
[解决办法]
mark
[解决办法]
select status,count(status) from table where status in (50,40,30) group by status
[解决办法]
up

[解决办法]
不错。
[解决办法]
liang521_1985() ( ) :
select sum(1) as bb into #c
from table
where status in (50,30,40)
group by status

select sum(bb) from #c

drop table #c
============================================
这是oracle的语法??


热点排行
Bad Request.