谁来帮我优化一下我的sql语句???

dai2jiang 2008-09-22 11:44:58
语句如下:
select count(*) from
(select t.mobile tm,sum(t.jifen)ts from t_jifen_detail t
where t.jifen>0 group by t.mobile)A,
(select j.mobile jm,sum(j.jifen)js from t_jifen_detail j
group by j.mobile)B
where A.ts=B.js;
...全文
127 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
caoleione 2008-09-22
  • 打赏
  • 举报
回复
Select Count(1)
From (Select j.Mobile Jm,
Sum(j.Jifen) Js,
Sum(Decode(Sign(Jifen), 1, Jifen, 0)) As Ts
From t_Jifen_Detail j
Group By j.Mobile)
Where Js = Ts
hyrongg 2008-09-22
  • 打赏
  • 举报
回复
语法没问题,感觉逻辑有问题

你要的结果好像就是
select t.mobile tm,sum(t.jifen) ts,count(1) from t_jifen_detail t where t.jifen>0 group by t.mobile;

里面的count(1)的值
列点数据,说明你要的结果,再帮你看看
nicholasgunn 2008-09-22
  • 打赏
  • 举报
回复
好像有点问题,上面的“=”不应该有。
nicholasgunn 2008-09-22
  • 打赏
  • 举报
回复
select mobile ,sum(jifen) from
t_jifen_detail
where mobile not in (select mobile from t_jifen_detail where jifen<=0 and rownum=1)
group by mobile

---------------------------------------------------
select mobile ,sum(jifen) from
t_jifen_detail a
where not exists(select * from t_jifen_detail b where a.mobile=b.mobile and b.jifen<=0)
group by mobile

好久不写sql了,都快忘了,记的好像可以这么写,你试试吧。
个人感觉第1种靠谱儿。
daifeng130 2008-09-22
  • 打赏
  • 举报
回复
除非积分有小于0的,否则你要的结果好像就是
select count(distinct mobile) from t_jifen_detail
where jifen>0
xiaowanglinxiao 2008-09-22
  • 打赏
  • 举报
回复
偶的理解:是不是要求积分大于零t.mobile的个数
select count(*) from
(select t.mobile tm,sum(t.jifen)ts from t_jifen_detail t
where t.jifen>0 group by t.mobile)

这个应该就可以了呀~1

17,380

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧