根據一個評價結果的字段來創建一張虛擬表來統計評價結果

座席工號 錄音編號 來電號碼 評價結果
0001 qww11 88888888 29
評價結果(很是滿意107077一、滿意1070772、通常1070773、不滿意1070774)

滿意度調查統計
座席工號 很是滿意 滿意 通常 不滿意 總計 滿意度
0001 86 69 14 11 180 93.88%
0002 93 30 6 10 139 92.80%

用sql語句來統計出來一張滿意度調查統計表: sql

select t.agent_id,
       sum(case
             when t.grade_id = 1070771 then
              1
             else
              0
           end) as Vsatisfied,
       sum(case
             when t.grade_id = 1070772 then
              1
             else
              0
           end) as Satisfied,
       sum(case
             when t.grade_id = 1070773 then
              1
             else
              0
           end) as General,
       sum(case
             when t.grade_id = 1070774 then
              1
             else
              0
           end) as Yawp,
       count(*) as scount,
       (sum(case
              when t.grade_id = 1070771 then
               1
              else
               0
            end) + sum(case
                          when t.grade_id = 1070772 then
                           1
                          else
                           0
                        end) + sum(case
                                      when t.grade_id = 1070773 then
                                       1
                                      else
                                       0
                                    end)) / count(*)*100 ||'%' as satisficing
  from tablename t
 group by t.agent_id
spa

注: agent_id 坐席工號,grade_id 評價結果
相關文章
相關標籤/搜索