分组查询的简单问题,求解~~~实在没分了

xyz_obj 2012-02-09 04:09:53

select count(*) as C_Count, u.fullname ,c.seat_jobnumber,DATEDIFF(ss,call_time,offhook_time) as diff_time from tb_call as c left join tb_user as u on u.username = c.seat_jobnumber where 1=1 and c.call_time >='2012-02-09' and c.call_time <'2012-02-09 23:59:59' group by c.seat_jobnumber,u.fullname,call_time

会报错:“列 'c.offhook_time' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。”
要怎么改才能达到我想要的这个结果呢?
...全文
49 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyz_obj 2012-02-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 szstephenzhou 的回复:]
SQL code
select count(*) as C_Count, u.fullname ,c.seat_jobnumber,DATEDIFF(ss,call_time,offhook_time) as diff_time from tb_call as c left join tb_user as u on u.username = c.seat_jobnumber where 1=1 ……
[/Quote]
我要的是分组后的结果
勿勿 2012-02-09
  • 打赏
  • 举报
回复
select count(*) as C_Count, u.fullname ,c.seat_jobnumber,DATEDIFF(ss,call_time,offhook_time) as diff_time from tb_call as c left join tb_user as u on u.username = c.seat_jobnumber where 1=1  and c.call_time >='2012-02-09' and c.call_time <'2012-02-09 23:59:59'
勿勿 2012-02-09
  • 打赏
  • 举报
回复
因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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