重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
1、創建測試表,
白朗ssl適用于網站、小程序/APP、API接口等需要進行數據傳輸應用場景,ssl證書未來市場廣闊!成為成都創新互聯的ssl證書銷售渠道,可以享受市場價格4-6折優惠!如果有意向歡迎電話聯系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
create table test_name(id varchar2(20),name varchar2(20), birthday date);
2、插入測試數據;
insert into test_name values(1, 'aa', to_date('1990-01-02 10:10:50','yyyy-mm-dd hh24:mi:ss'));
insert into test_name values(2, 'bb', to_date('1987-02-02 10:01:25','yyyy-mm-dd hh24:mi:ss'));
insert into test_name values(3, 'cc', to_date('2000-01-25 09:01:25','yyyy-mm-dd hh24:mi:ss'));
commit;
3、編寫語句,根據birthday字段進行升序;
select * from test_name t order by birthday;
4、編寫語句,根據birthday字段進行降序;
select * from test_name t order by birthday desc;
計算和排序 可以用兩個表達式的;計算列作為 select 的子句; (endTime-nowTime) 作為 order by 的子句
如果提示 order by 不是查詢的內容,可以用子查詢 ,先 select 出來兩個列,然后 在按照 (endTime-nowTime) 的倒敘排列
排序的話,用order by來處理即可。
比如:
col
a123
a234
b999
b335
select?*?from?tablename?order?by?col;
結果就是
col
a123
a234
b335
b999
如果按倒序排列:
select?*?from?tablename?order?by?col?desc;
結果就是
col
b999
b335
a234
a123
先排字母,然后再排漢字。是a,b,阿,吧。按照字符的ASCII碼的順序來排序。順序的時候,按照ASCII碼由小到大排序。倒序的時候,按照ASCII碼由大到小排序。
如果表非常大,需要用rownum查詢指定的幾條,下面命令可以實現
select * from(
select *
from T_NB_COPY t
order by create_time desc
) b where rownum = 5
去重及時間段獲取
select distinct t.device_id from T_RECEIVE_LOG t where ?t.receive_time = to_date('2018-02-28 00:00:00','yyyy-mm-dd hh24:mi:ss') and t.receive_time = to_date('2018-02-27 00:00:00','yyyy-mm-dd hh24:mi:ss')
使用倒序索引提升ORDER BY DESC性能
使用倒序索引(INDEX DESC),可以大幅提升帶有order by desc子句的SQL語句性能。
舉例
1、表名:test_t,有一字段名為object_id
2、總數據量:580000行,segment_size:72MB
3、Where條件(Owner=’SYS’ and Object_id50000)的行數:32472行
4、SQL語句:select * from test_t where owner='SYS' and object_id 50000 order by object_id desc
5、希望借助倒序索引,提升order by object_id desc的性能
希望能幫到你。