select 用户名,通话时长,被叫号码 from table where 呼入/呼出=呼出 and 通话时长 = (select max(通话时长)from table where 呼入/呼出=呼出 )
select 用户名,max(通话时长),被叫号码 from table where 呼入/呼出=呼出
select 用户名,max(通话时长),被叫号码 from table where 呼入/呼出=呼出 group by 用户名,被叫号码
jtkk 的方法只能取得一条记录吧,与其如此麻烦不如: SELECT TOP 1 用户名,通话时长,被叫号码 FROM table WHERE 呼入/呼出=呼出 Order By 通话时长 DESC用一句 SQL 显示所有用户的最长呼出记录,还真不好办。左手的方法所得到的被叫号码不一定对应于最大通话时长。试试: select a.用户名, 最大通话时长, 被叫号码 from table as a inner join (select 用户名, max(通话时长) as 最大通话时长 from table group by 用户名) as b on a.用户名 = b.用户名 and a.通话时长 = 最大通话时长 where a.呼入/呼出=呼出
select 用户名,max(通话时长),被叫号码 from tel where 呼入/呼出=呼出 group by 用户名,被叫号码 该SQL已经测试考虑到字段名是英文,如字段中间有空格,如字段名为:First Name,在SQL语句中一 定要加上中括号如:[First Name] Select [First Name] from table √ Select First Name from table ×
你用的是什么数据库引擎,会不支持 Join 句法。试试:select a.用户名, 最大通话时长, 被叫号码 from table as a, [select 用户名, max(通话时长) as 最大通话时长 from table group by 用户名] as b where a.呼入/呼出=呼出 And a.用户名 = b.用户名 and a.通话时长 = 最大通话时长
select a.用户名, a.通话时长, a.被叫号码 from table as a inner jion (select 用户名,max(通话时长) as 最大时长 from table where 呼入/呼出=呼出 group by 用户名) as b on a.用户名 = b.用户名 where a.通话时长 = b.最大时长
不支持“Join”??? Access啊?不可能啊,这样也应该可以:select a.用户名, a.通话时长, a.被叫号码 from table as a inner jion (select 用户名,max(通话时长) as 最大时长 from table where 呼入/呼出=呼出 group by 用户名) as b on a.用户名 = b.用户名 and a.通话时长 = b.最大时长
再来一个试试: select 用户名, 通话时长, 被叫号码 from table where 通话时长 in (select max(通话时长) from table where 呼入/呼出=呼出 group by 用户名)
select 用户名,通话时长,被叫号码 from table where 呼入/呼出=呼出 and 通话时长 = (select max(通话时长)from table where 呼入/呼出=呼出 ) 这个应该可行啊
就一个表也弄出这么多复杂的SQL语句,呵呵
对:palmkey(终日而思,孰如须臾所学) “select 用户名,max(通话时长),被叫号码 from tel where 呼入/呼出=呼出 group by 用户名,被叫号码 该SQL已经测试”这条语句的执行结果 并不是返回最长通话时间的那条纪录,而是返回用户所有的通话记录。vbman2003(家人) 再来一个试试: select 用户名, 通话时长, 被叫号码 from table where 通话时长 in (select max(通话时长) from table where 呼入/呼出=呼出 group by 用户名)这个返回结果也不唯一我只想每个用户返回一条记录(即通话时间最长的那一条) 同时显示用户名、时长、号码。
噢,对了,最大通话时间相同时会不唯一。再改一下:select 用户名, 通话时长, max(被叫号码) as 号码 from table where 通话时长 in (select max(通话时长) from table where 呼入/呼出=呼出 group by 用户名) group by 用户名, 通话时长
晕了。这样就应该可以了: select 用户名,max(通话时长) as 时长,max(被叫号码) as 号码 from table where 呼入/呼出=呼出 group by 用户名
select 用户名,通话时长,被叫号码 from table t1 inner join (select 用户名,max(通话时长) as 通话时长 from table group by 用户名) t2 on t1.用户名=t2.用户名 and t1.通话时长=t2.通话时长 我觉得最好在该表中,如果有关键字,最好用关键字来匹配
"select a.userid as 用户名,a.howtime as 通话时间,a.calledno as 被叫号码 from TabRecords as a inner jion (select userid,max(howtime) as Ltime from TabRecords where inorout=0 group by userid) as b on a.userid=b.userid and a.howtime=b.Ltime" 我这样写的,可是执行时提示:“JOIN操作语法错误”。
标准答案来了: select a.用户名,a.最长时长,b.被叫号码 from (select 用户名,max(通话时长) as 最长时长 from sheet1 where 呼入呼出='呼出' group by 用户名 ) a inner join sheet1 b on a.用户名=b.用户名 and a.最长时长=b.通话时长
楼上的代码,当一个用户的最长通话时间有两个(相等),而号码不一样时依然不唯一。这样:select a.用户名, a.通话时长, amx(a.被叫号码) as 号码 from table as a inner join (select 用户名,max(通话时长) as 最大时长 from table where 呼入/呼出=呼出 group by 用户名) as b on a.用户名 = b.用户名 and a.通话时长 = b.最大时长 group by a.用户名, a.通话时长ORselect 用户名, 通话时长, max(被叫号码) as 号码 from table where 通话时长 in (select max(通话时长) from table where 呼入/呼出=呼出 group by 用户名) group by 用户名, 通话时长
from table
where 呼入/呼出=呼出 and
通话时长 = (select max(通话时长)from table where 呼入/呼出=呼出 )
from table
where 呼入/呼出=呼出
group by 用户名,被叫号码
SELECT TOP 1 用户名,通话时长,被叫号码 FROM table WHERE 呼入/呼出=呼出 Order By 通话时长 DESC用一句 SQL 显示所有用户的最长呼出记录,还真不好办。左手的方法所得到的被叫号码不一定对应于最大通话时长。试试:
select a.用户名, 最大通话时长, 被叫号码
from table as a inner join
(select 用户名, max(通话时长) as 最大通话时长 from table group by 用户名) as b
on a.用户名 = b.用户名 and a.通话时长 = 最大通话时长
where a.呼入/呼出=呼出
谢谢你!我试过了,可是它提示“不支持链接表达式”。我用的是Access2000
该SQL已经测试考虑到字段名是英文,如字段中间有空格,如字段名为:First Name,在SQL语句中一
定要加上中括号如:[First Name]
Select [First Name] from table √
Select First Name from table ×
from table as a,
[select 用户名, max(通话时长) as 最大通话时长 from table group by 用户名] as b
where a.呼入/呼出=呼出 And a.用户名 = b.用户名 and a.通话时长 = 最大通话时长
from table as a
inner jion (select 用户名,max(通话时长) as 最大时长 from table where 呼入/呼出=呼出 group by 用户名) as b
on a.用户名 = b.用户名
where a.通话时长 = b.最大时长
from table as a
inner jion (select 用户名,max(通话时长) as 最大时长 from table where 呼入/呼出=呼出 group by 用户名) as b
on a.用户名 = b.用户名 and a.通话时长 = b.最大时长
我感觉左手的方法就可以了.
还有,Access的引擎与SQL的SQL语法处理不一样.有些Sql语句不能通过,你必需显示的写出相应的子表.
select 用户名, 通话时长, 被叫号码
from table
where 通话时长
in (select max(通话时长) from table where 呼入/呼出=呼出 group by 用户名)
from table
where 呼入/呼出=呼出 and
通话时长 = (select max(通话时长)from table where 呼入/呼出=呼出 )
这个应该可行啊
“select 用户名,max(通话时长),被叫号码 from tel where 呼入/呼出=呼出 group by 用户名,被叫号码
该SQL已经测试”这条语句的执行结果 并不是返回最长通话时间的那条纪录,而是返回用户所有的通话记录。vbman2003(家人)
再来一个试试:
select 用户名, 通话时长, 被叫号码
from table
where 通话时长
in (select max(通话时长) from table where 呼入/呼出=呼出 group by 用户名)这个返回结果也不唯一我只想每个用户返回一条记录(即通话时间最长的那一条) 同时显示用户名、时长、号码。
from table
where 通话时长
in (select max(通话时长) from table where 呼入/呼出=呼出 group by 用户名)
group by 用户名, 通话时长
select 用户名,max(通话时长) as 时长,max(被叫号码) as 号码
from table
where 呼入/呼出=呼出
group by 用户名
(select 用户名,max(通话时长) as 通话时长 from table group by 用户名) t2
on t1.用户名=t2.用户名 and t1.通话时长=t2.通话时长 我觉得最好在该表中,如果有关键字,最好用关键字来匹配
我这样写的,可是执行时提示:“JOIN操作语法错误”。
select a.用户名,a.最长时长,b.被叫号码
from (select 用户名,max(通话时长) as 最长时长
from sheet1
where 呼入呼出='呼出'
group by 用户名
) a inner join sheet1 b
on a.用户名=b.用户名 and a.最长时长=b.通话时长
from table as a
inner join (select 用户名,max(通话时长) as 最大时长 from table where 呼入/呼出=呼出 group by 用户名) as b
on a.用户名 = b.用户名 and a.通话时长 = b.最大时长
group by a.用户名, a.通话时长ORselect 用户名, 通话时长, max(被叫号码) as 号码
from table
where 通话时长
in (select max(通话时长) from table where 呼入/呼出=呼出 group by 用户名)
group by 用户名, 通话时长