效能測試常用sql技巧_Oracle

來源:互聯網
上載者:User

標籤:nbsp   cat   order   結果   art   group by   _for   orm   建立   

  做了一段時間的效能測試,把自己在效能測試過程中,使用到的Oracle中用到的sql語句整理一番,做個備忘;

(1)多個欄位以某種格式拼接

  "||"字串拼接符;

  樣本:將“id”及“code”用逗號拼接: select t.id||‘,‘||t.code from OTable t;  

  備忘:MySQL中使用 concat()函數,select concat(t.id,‘,‘,t.code) from MTable t;

(2)以某一個欄位為維度統計數量

  count + group by;

  樣本:統計某個建立人對應的資料數量:select t.creatorname,count(1) from OTable t (此處省去where條件查詢) group by t.creatorname;

(3)統計每秒產生的資料的數量,並按數量由大到小進行排序-----------結果常用於效能測試目標TPS確定的參考值;

  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;

 

效能測試常用sql技巧_Oracle

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.