关于统计的查询

redman0607 2005-10-09 12:25:10
我有一个表tb_client_db 里边的字段有 工号、姓名、成功量、实际工时、工效、拨打时长、工时占有率、回单量、成功率(%)几个字段.
比如查询的结果是
业务指标 成功量 实际工时 工效 拨打时长 工时占有率 回单量 成功率(%)
全台均值 52 78 4.5 75 76 110 80
当前最高指标 60 80 6 80 80 120 85
个人当前指标 50 70 4 50 70 100 80
个人位列名次 统计 统计 统计 统计 统计

个人位列名次 中的统计就是统计该量在全台的名次(不重复派名)

不用游标,用sql语句怎么实现?

...全文
77 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2005-10-09
  • 打赏
  • 举报
回复
select a.工号,a.姓名,b.*
from tb_client_db a, (
select
业务指标='全台均值',
成功量=avg(成功量),
实际工时=avg(实际工时),
工效=avg(工效),
拨打时长=avg(拨打时长),
工时占有率=avg(工时占有率),
[成功率(%)]=avg([成功率(%)])
from tb_client_db
union all
select
业务指标='当前最高指标',
成功量=max(成功量),
实际工时=max(实际工时),
工效=max(工效),
拨打时长=max(拨打时长),
工时占有率=max(工时占有率),
[成功率(%)]=max([成功率(%)])
from tb_client_db
)b
union all
select 工号,姓名,
业务指标='个人当前指标',
成功量=(成功量),
实际工时=(实际工时),
工效=(工效),
拨打时长=(拨打时长),
工时占有率=(工时占有率),
回单量=(回单量),
[成功率(%)]=([成功率(%)])
from tb_client_db
union all
select 工号,姓名,
业务指标='个人位列名次',
成功量=(select count(*) from tb_client_db where 成功量>=a.成功量),
实际工时=(select count(*) from tb_client_db where 实际工时>=a.实际工时),
工效=(select count(*) from tb_client_db where 工效>=a.工效),
拨打时长=(select count(*) from tb_client_db where 拨打时长>=a.拨打时长),
工时占有率=(select count(*) from tb_client_db where 工时占有率>=a.工时占有率),
回单量=(select count(*) from tb_client_db where 回单量>=a.回单量),
[成功率(%)]=(select count(*) from tb_client_db where [成功率(%)]>=a.[成功率(%)])
from tb_client_db a
order by 1,2,3

34,575

社区成员

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

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