スキーマ

show index from [テーブル名];

日時

  • 曜日別
    select date_format(insert_date, '%w') as day_of_week, count(*) from test_table group by day_of_week;
  • 時間帯別
    select date_format(insert_date, '%H') as hour, count(*) from test_table group by hour;

文字列

文字列切り出し・結合

  • ハイフンが入っていない郵便番号の文字列(数字のみ7桁)を抽出して、ハイフン入りにした文字列を表示
    select post_number, concat(substring(post_number,1,3), '-', substring(post_number,4,4)) from company where post_number regexp '^[[:digit:]]{7}$';
  • ハイフンが入っていない郵便番号の文字列(数字のみ7桁)を、ハイフン入りにした文字列に update
    update company set post_number = concat(substring(post_number,1,3), '-', substring(post_number,4,4)) where post_number regexp '^[[:digit:]]{7}$';

型変換

  • 小数点の数字を文字列カラムに set した場合、勝手に浮動小数点に変換される
    ex) 150.023 -> 151.0229949951172

DELETE

LIMIT row_count オプション

  • MySQL 特有
  • コントロールがクライアントに戻される前に、削除されるべき最大行数をサーバに伝える
  • 与えられた DELETE ステートメントに時間がかかりすぎない事を保障します
  • 影響される行数が LIMIT 値よりも少なくなるまで DELETE ステートメントを繰り返す

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2022-07-14 (木) 11:34:30 (649d)