zoukankan      html  css  js  c++  java
  • Oracle 在使用pivot时,注意事项

    a)         Pivot的时候,实际上也是一次分组,并且可以通过聚簇函数来实现统计

    b)         Pivot在取列名的时候,如果别名有汉字,要用双引号括起来,或者不用双引号

    c)         如果对应的字段值为非数字或者字母,记得要用单引号引起来,比如下面的’A’

    select *

      from (select case

                     when a.score >= 220 and a.score <= 330 then

                      '(220,330)'

                     when a.score >= 630 and a.score <= 710 then

                      '(630,710)'

                     when a.score < 220 then

                      '其他'

                     else

                      '(' || (ceil((a.score - 330) / 20) * 20 + 330) || ',' ||

                      (ceil((a.score - 330) / 20 + 1) * 20 + 330) || ')'

                  

                   end 分数段,

                   b.score

              from SUBJECTREGISTER a

              left join SUBJECTREGISTER b

                on a.candidatesid = b.candidatesid

             WHERE a.testid = '181'

               and a.CAMPUSCODE LIKE '12%'

               AND a.SUBJECTCODE != 'S'

               AND a.SUBJECTCODE != 'F'

               AND (a.SCORE != '0' AND a.SCORE IS NOT NULL and

                   b.score IS NOT NULL)

               AND (b.SUBJECTCODE = 'S' or b.SUBJECTCODE = 'F')) pivot(count(SCORE) FOR SCORE IN('A' "A",

                                                                                                 'A+' "A+",

                                                                                                 'B' "B",

                                                                                                 'B+' "B+",

                                                                                                 'C' "C",

                                                                                                 'C+' "C+",

                                                                                                 'D' "D",

                                                                                                 'D+' "D+"))

     ORDER BY 分数段

  • 相关阅读:
    iphone那些事儿
    【转】我面试过最出色的项目主管,入职半年就离职了。
    net::ERR_ABORTED 404 (Not Found)
    四大名著
    测试心理状态
    typescript那些事儿
    flexbox父盒子flex-direction属性
    flexbox父盒子align-content属性
    flexbox父盒子flex-wrap属性
    flexbox父盒子align-items属性
  • 原文地址:https://www.cnblogs.com/hobby0524/p/8949407.html
Copyright © 2011-2022 走看看