Oracleラーニングノート:使用する関数と統計文


  • groupbyを使用したクラス別統計数:
  • SELECT type_id,COUNT(1) FROM core_tbl GROUP BY type_id;
  • ある日のデータレコードを問い合わせる(時間対)
  • --   9 12    
    select a.* from tbl_test a where a.chk_date between to_date('2017-09-12 00:00:00','yyyy-MM-dd hh24:mi:ss') and to_date('2017-09-12 23:59:59','yyyy-MM-dd hh24:mi:ss');
    
    select a.* from tbl_test a where to_char(a.chk_date,'yyyy-MM--dd')='2017-09-12';
  • substr関数の応用
  • select substr('abcqwedabc',1,3),substr('dsad',-3,3) from dual;
  • 統計あるクラスがどれだけ大きいかのデータ(havingを使用)
  • select type_name,count(type_name) from tbl_test group by type_name having count(type_name)>5;
  • サブクエリクエリ使用量テーブル関連データを含む(where inを使用):サブクエリは複数行を返すため、inキーを使用する:
  • .
    select * from a where a.aname in (select bname from b )