pgsql 同比或者下降

Posted IT的鱼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pgsql 同比或者下降相关的知识,希望对你有一定的参考价值。

  WITH total_t AS (
          select COUNT ( T.* ) AS COUNT FROM table t
 t.create_time BETWEEN to_timestamp( #startTime,'yyyy-mm-dd')
                 and to_timestamp( #endTime,'yyyy-mm-dd')

        ),
        type_hbc_t as(
     select COUNT ( T.* ) AS COUNT FROM table t
   t.create_time BETWEEN to_timestamp( #startTime,'yyyy-mm-dd')
                 and to_timestamp( #endTime,'yyyy-mm-dd')
        ),
        type_tbc_t as (
          select COUNT ( T.* ) AS COUNT FROM table t
 t.create_time BETWEEN to_timestamp( #startTime,'yyyy-mm-dd')
                 and to_timestamp( #endTime,'yyyy-mm-dd')
        )
        SELECT
        t2.count as total,
      (case when t3.COUNT - t2.COUNT > 0 then 'up' else 'down' end ) as hb_up_down,
		(case when t4.COUNT - t2.COUNT > 0 then 'up' else 'down' end ) as tb_up_down,
         CASE WHEN t3.COUNT - t2.COUNT > 0 THEN round((t3.COUNT - t2.COUNT)*100.0/t2.count::numeric ,2)
        else round(abs(t3.COUNT - t2.COUNT)*100.0/t2.count::numeric ,2)  END AS hb,
         CASE WHEN t4.COUNT - t2.COUNT > 0 THEN round((t4.COUNT - t2.COUNT) *100.0/t2.count::numeric ,2)
        else round(abs(t4.COUNT - t2.COUNT)*100.0/t4.count::numeric ,2)  END AS tb
        FROM total_t t2, type_hbc_t t3,type_tbc_t t4 





<sql id="hbConditionSql">
        <where>
            <if test="type != null and type != '' and type=='1'.toString()">
                <![CDATA[ T.create_time BETWEEN  #startTime::timestamp + '-1 day'
            and  #endTime::timestamp + '- 1 day' ]]>
            </if>

            <if test="type != null and type != '' and type=='2'.toString()">
                <![CDATA[ T.create_time BETWEEN  #startTime::timestamp + '-1 week'
            and  #endTime::timestamp + '- 1 week' ]]>
            </if>

            <if test="type != null and type != '' and type=='3'.toString()">
                <![CDATA[ T.create_time BETWEEN  #startTime::timestamp + '-1 month'
            and  #endTime::timestamp + '-1 month' ]]>
            </if>

            <if test="type != null and type != '' and type=='4'.toString()">
             <![CDATA[ T.create_time BETWEEN  #startTime::timestamp + '-3 month'
              and  #endTime::timestamp + '-3 month' ]]>
            </if>

            <if test="type != null and type != '' and type=='4'.toString()">
                <![CDATA[ T.create_time BETWEEN  #startTime::timestamp + '-1 year'
              and  #endTime::timestamp + '-1 year' ]]>
            </if>

        </where>
    </sql>

以上是关于pgsql 同比或者下降的主要内容,如果未能解决你的问题,请参考以下文章

pgsql 同比或者下降

马化腾去年年薪同比下降 25%,腾讯的下一步怎么走?

映宇宙2022年营收63亿元:同比下降三成,毛利率提升4.3个百分点

青浦社区的人脸识别系统监控渐显成效,还意外抓到一处偷倒垃圾线索

国际新闻|PostgreSQL持续强势上涨,榜前十位同比涨幅第一

华为开发者大会9月10日举行,将公布鸿蒙OS和EMUI 11