现有两个表:
t1(user_mobile,total_score...);
t2(user_mobile,trans_counts...);现要查询出每个user_mobile的total_score,sum(trans_counts),其中有部分号码只存在于t1表而不在t2表中,不在t2表中
user_mobile的sum(trans_counts)显示为空或者0。
t1(user_mobile,total_score...);
t2(user_mobile,trans_counts...);现要查询出每个user_mobile的total_score,sum(trans_counts),其中有部分号码只存在于t1表而不在t2表中,不在t2表中
user_mobile的sum(trans_counts)显示为空或者0。
解决方案 »
- win7下安装oracle 11g r2 报错:此卷上用于所选 Oracle 主目录的磁盘空间不足
- oracle 监听错误,附日志信息。高手帮忙~~
- 谁用过oracle触发器?
- 两个数据库表格间的数据查询
- ORACLE 日期参数格式怎么计算啊?各位高手,散分了
- oracle数据库中恢复记录表失败
- 循环ebs的AR会计期,分期显示每一期天数
- ◆◆◆◆◆◆在SQLplus中读取存储过程或包(体)◆◆◆◆◆◆
- oracle 9i是否必须购买服务,如果同一个oracle 数据库是否可以在两个或两个以上的服务器上安装?
- 默认安装oracle8.05.运行SQL PLUS后,使用帐号internal/oracle登录.无法建表.[更详细状况点击...]
- 用户名为数字时不能访问的问题,急!!
- 请教一个连接oracle 10g的问题!
from(
select t1.user_mobile,sum(t1.total_score) total_score,0 trans_counts from t1 group by t1.user_mobile
union all
select t2.user_mobile,0,sum(t2.trans_counts) trans_counts from t2 group by t2.user_mobile
) group by user_mobile
T1.total_score,
DECODE(T3.sum_trans_counts,NULL,0,T3.sum_trans_counts)
FROM
T1,
(SELECT
T2.user_mobile,
SUM(T2.trans_counts)
FROM
T2
GROUP BY T2.user_mobile) T3
WHERE
T1.user_mobile = T3.user_mobile(+)
nvl(sum_counts,0) as
from t1,
(
select t2.user_mobile,
sum(t2.trans_counts) as sum_counts
from t2
group by t2.user_mobile
)tt
where t1.user_mobile = tt.user_mobile(+);
Select T1.user_mobile,sum(T1.total_score),
DECODE(sum(T2.trans_counts),NULL,0,sumT2.trans_counts))
FROM T1, T2
Where T1.user_mobile = T2.user_mobile(+)
Group By T1.user_mobile,T1.total_score;这样结果也是一样的,那不是更加简单?
Select T1.user_mobile,sum(T1.total_score), sum(nvl(T2.trans_counts,0))
FROM T1, T2
Where T1.user_mobile = T2.user_mobile(+)
Group By T1.user_mobile;
on t1.user_mobile =t3.user_mobile
SELECT T1.USER_MOBILE,T1.TOTAL_SCORE,DECODE(T3.TRANS_COUNTS,0)
FROM T1,
(SELECT USER_MOBILE,SUM(TRANS_COUNTS) AS TRANS_COUNTS FROM T2 GROUP BY USER_MOBILE) T3
WHERE T1.USER_MOBILE=T3.USER_MOBILE(+)