select col1,count(*) cnt1,sum(decode(col2,1,1,0)) cnt2,null,null
from table1 group by col1
union all
select col1,null,null,count(*) cnt3,sum(decode(col1,1,1,0)) cnt4
from table2 group by col1;
from table1 group by col1
union all
select col1,null,null,count(*) cnt3,sum(decode(col1,1,1,0)) cnt4
from table2 group by col1;
解决方案 »
- 纵向排列如何改成横向的?????????
- 求一个 sql ~~~~~~~!
- asp读取oracle clob数据的问题
- 求助在这种表结构下如何写出Sql语句进行汇总统计,希望高手指点。
- 求助:函数数据类型问题
- 急求 oeacle 数据库
- 100分求oracle 9i 在 RedHat 7.1下的性能优化。
- ORACLE, SYBASE ANYWHERE, SQL Server的比较
- 我在程序中想用oracle提供的库去连接ORACLE,但是我不知道怎么做?我现在也知道怎么弄?大家帮帮我吧
- 未在本地计算机上注册“OraOLEDB.Oracle.1”提供程序?在线等待!
- sql問題
- sql语句,高手快帮我看看,急!!!!!
from table1 group by col1
union all
select col1,null,null,count(*) cnt3,sum(decode(col1,1,1,0)) cnt4
from table2 group by col1;
而且上面语句执行时也确实出错:ora-01790:expression mus have same datatype as corresponding expression。
union all前后的语句正常执行,但UNION时出错。
from table1 group by col1
union all
select col1,0,0,count(*) cnt3,sum(decode(col1,1,1,0)) cnt4
from table2 group by col1;
create view col_cnt as
select col1,count(*) cnt1,sum(decode(col2,1,1,0)) cnt2,0 cnt 3,0 cnt4
from table1 group by col1
union all
select col1,0,0,count(*) cnt3,sum(decode(col1,1,1,0)) cnt4
from table2 group by col1;然后在用sql语句进行计算。
select col1,sum(cnt1) cnt1,sum(cnt2) cnt2,sum(cnt3) cnt3,sum(cnt4)cnt4 from col_cnt group by col1;
from table1 a,table2 b
where
参考这个思路,你的表之间的关系没有说清楚,语句没法写。