zoukankan      html  css  js  c++  java
  • 性能测试常用sql语句

      做了一段时间的性能测试,把自己在性能测试过程中,使用到的Oracle中用到的sql语句整理一番,做个备忘;

    (1)多个字段以某种格式拼接

      Oracle方式:"||"字符串拼接符;

      示例:将“id”及“code”用逗号拼接: select t.id||','||t.code from OTable t;  

      MySQL方式:使用 concat()函数;

      示例:select concat(t.id,',',t.code) from MTable t;

    (2)以某一个字段为维度统计数量

      Oracle方式:count + group by;

      示例:统计某个创建人对应的数据数量:select t.creatorname,count(1) from OTable t (此处省去where条件查询) group by t.creatorname;

    (3)统计每秒生成的数据的数量,并按数量由大到小进行排序-----------结果常用于性能测试目标TPS确定的参考值;

      Oracle方式:count + group by + order by;(修改下面的sql中to_char的格式,可修改精确度为min或者hour)

      示例:select to_char(t.Createtime,'yyyy-mm-dd hh24:mi:ss'),COUNT(1) from OTable t where 

    to_char(t.Createtime,'yyyy-mm-dd hh24:mi:ss') >='2016-01-01 00:00:00' and

    to_char(t.Createtime,'yyyy-mm-dd hh24:mi:ss') <='2016-12-31 23:59:59' 

    group by to_char(t.Createtime,'yyyy-mm-dd hh24:mi:ss')

    order by count(1) desc;

      MySQL方式:DATE_FORMAT+ group by + order by;(修改DATE_FORMAT中的第二个参数,可修改精确度为min或者hour)

      示例:select DATE_FORMAT(start_time,'%Y%m%d %H%i%s') iSecond,count(id) as icount

    from MTable t where t.start_time BETWEEN '2017-06-01 00:00:00' and '2017-06-01 23:59:59' 

    group by iSecond

    order by icount desc;

    (4)统计某张表两个时间的时间差

      MySQL方式:TIMESTAMPDIFF()函数,计算两个时间之间的差值,若第一个时间参数值晚于第二个时间参数值,则结果为负值;

      示例:SELECT t.START_TIME, t.FINISH_TIME,

    TIMESTAMPDIFF(SECOND, t.START_TIME, t.FINISH_TIME) AS `iSecond` 

    from MTable t where t.start_time BETWEEN '2017-05-10 00:00:00' and '2017-06-30 23:59:59';

    (5)拉取结果集前N行

      Oracel方式:rownum <= N;

      示例:update crm_issue t set t.OPERATORNUMBER = '****' where t.expresscode like '2017%' and  rownum<=300000

      MySQL方式:limit 0,N;

      示例:SELECT  * from erp_so_header h where  h.soSyncStatus = 'SUCCESS' order by h.code desc limit 0,1000

  • 相关阅读:
    python base64加密文本内容(1)
    python 翻译爬虫
    json为txt文本加密
    python json
    repr()函数
    linux 基本命令
    测试管理工具--禅道
    测试基础理论
    测试用例--场景法
    测试用例--测试大纲(提纲)法
  • 原文地址:https://www.cnblogs.com/xpp142857/p/6675809.html
Copyright © 2011-2022 走看看