如何得到我想要的数据?各位帮忙呀

xu_guanghui 2001-10-24 03:02:23
我在进行统计的时候有这样一张表,表里的数据是关于电话费用的表,表中主要字段有
主叫好码, 被叫号码, 通话开始时间,通话时长,金额 
(calling_nbr,called_nbr, start_time duration charge)
现在表中有这样一些话单,主叫号码相同,被叫号码不同,起始时间相同,这些话单属于
呼叫转移的话单,它的被叫号码一个是打普通长途电话的如:0335-8059740 一个是打手机的电话如:013056149973
我现在要统计出这样的话单,且是打手机的数据(只要主叫号码,和被叫号码就可以了)
SQL该如何去写呀,(该表肯定是满足第三范式要求的)
先谢了
...全文
98 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
spyer 2001-10-24
  • 打赏
  • 举报
回复
这样行不行,有疑问可以发E-MAIL给我,no1_zhang@etang.com

select table_a.calling_nbr,
table_a.called_nbr,
table_a.start_time,
table_a.duration,
table_a.charge
from table_a,
(select calling_nbr,start_time
from table_a
group by calling_nbr,start_time
having count(*)>1) as temp_a
where table_a.calling_nbr=temp_a.calling_nbr and
table_a.start_time=temp_a.start_time and
table_a.called_nbr like '手机号码';

昵称被占用了 2001-10-24
  • 打赏
  • 举报
回复
试过以上方法没有!
xu_guanghui 2001-10-24
  • 打赏
  • 举报
回复
我的表中的主键没有写出来,他是ticket_id 和我要统计的数据没有关系
我写的具体一点吧
calling_nbr called_nbr start_time
3576809 05172341732 2001/09/21 10:30:30
3576809 02154084505 2001/08/21 6:44:30
3576809 013905266336 2001/08/21 6:44:30
3757655 05168828386 2001/09/01 8:44:30
3576555 013005266336 2001/08/21 6:55:30
3576555 03358065491 2001/08/21 6:55:30
当然表中的数据很多,有几百万条,通过查询我想得到的结果是
3576809 013905266336 2001/08/21 6:44:30
3576555 013005266336 2001/08/21 6:55:30
请各位帮忙!




icevi 2001-10-24
  • 打赏
  • 举报
回复
我用的是SQL SERVER中,charindex 是用来返回一个字符在另一个字符串中出现的位置.你可以在ORACLE中类似的函数来代替.
因为不知道用什么规律来判断是手机号还是座机号,就认为电话号码中带'-'的是座机号,你可以根据实际情况改写一下.
昵称被占用了 2001-10-24
  • 打赏
  • 举报
回复
你的主键到底是什么?
昵称被占用了 2001-10-24
  • 打赏
  • 举报
回复
To:xu_guanghui(小风) 
"主叫号码相同,被叫号码不同,起始时间相同",
"因为一个主叫号码,和一个通话开始时间唯一确定一条记录,不需要在分组了"
你自相矛盾了!
xu_guanghui 2001-10-24
  • 打赏
  • 举报
回复
to icevi 
     charindex  是什么意思呀?我在ORACLE试的时候提示 MISSING EXPRESSION 错误
to argin
在你的sql 语句中group by 是不起作用的,因为一个主叫号码,和一个通话开始时间唯一确定一条记录,不需要在分组了
icevi 2001-10-24
  • 打赏
  • 举报
回复
笔误,改:
select t1.calling_nbr,t1.called_nbr
from nbr_tab t1
where charindex('-',t1.called_nbr)<>0
and exist (select * from nbr_tab t2
where t2.calling_nbr=t1.calling_nbr
and t2.start_time =t1.start_time
and t2.called_nbr<>t1.called_nbr
)

icevi 2001-10-24
  • 打赏
  • 举报
回复
select t1.calling_nbr,t1.called_nbr
from nbr_tab t1
where charindex('-l',t1.called_nbr)<>0
and exist (select * from nbr_tab t2
where t2.calling_nbr=t1.calling_nbr
and t2.start_time =t1.start_time
and t2.called_nbr<>t1.called_nbr
)
昵称被占用了 2001-10-24
  • 打赏
  • 举报
回复
select a.主叫好码,a.被叫号码 from 电话费用表 a, 电话费用表 b
where a.主叫好码=b.主叫好码
and a.被叫号码<>b.被叫号码
and a.通话开始时间=b.通话开始时间
and (a.被叫号码 like '013%' or a.被叫号码 like '13%')
and (b.被叫号码 not like '013%' and b.被叫号码 not like '13%')

其中 (a.被叫号码 like '013%' or a.被叫号码 like '13%') 表示是手机号码
(b.被叫号码 not like '013%' and b.被叫号码 not like '13%')表示不是手机号码
如果有其他方法判断就有你自己的方法.


东土 2001-10-24
  • 打赏
  • 举报
回复
没有看明白!

是不是这个意思?
select calling_nbr,called_nbr from nbr_tab where
called_nbr like '013%' or called_nbr like '13%' --手机号码
group by calling_nbr,called_nbr,start_time....

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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