MySQLでtimestamp型のカラムを検索してみる
timestamp型は形式として’YYYY-MM-DD HH:MM:SS'となっています。
そこで年月までだとか年月日まで検索したいな〜っと思った時があったので、その時使ったSQL文を載せておきます。
1.年月で検索したい場合
SELECT * FROM table_name WHERE timestamp_column LIKE '2018-07%';
2.年月日で検索したい場合
SELECT * FROM table_name WHERE timestamp_column LIKE '2018-07-31%';
whereのlike句の後方一致で検索できます。
しかし、timestamp型の落とし穴があります。
SELECT * FROM table_name WHERE timestamp_column BETWEEN '2018-07-01' AND '2018-07-31';
とすると、2018年7月1日から2018年7月31日ではなく、2018年7月1日から2018年7月30日の範囲で検索されてしまいます。
その理由として、timestamp型で上記のように年月日で記述すると、勝手に00:00:00が補完されるみたいです。
なので、2018年7月1日から2018年7月31日のデータを検索したい場合は、
SELECT * FROM table_name WHERE timestamp_column BETWEEN '2018-07-01' AND '2018-08-01';
とする必要があります。
brew doctorがめっちゃ警告してくる
インストールの問題のチェックを行うコマンドである「brew doctor」。
Homebrewでインストールしたパッケージが上手く挙動しなかったので、試しにターミナルに打ち込んでみました。
そしたら大量の警告が出てきて気持ちが悪かったので、一つずつ解決したことを備忘録として残しておきたいと思います。
目指せ、「Your system is ready to brew.」!
まずはbrew doctorでエラーの確認。
Please note that these warnings are just used to help the Homebrew maintainers with debugging if you file an issue. If everything you use Homebrew for is working fine: please don't worry or file an issue; just ignore this. Thanks! Warning: The following directories are not writable: /usr/local/lib/pkgconfig This can happen if you "sudo make install" software that isn't managed by Homebrew. If a formula tries to write a file to this directory, the install will fail during the link step. You should change the ownership of these directories to your account. sudo chown -R $(whoami) /usr/local/lib/pkgconfig Warning: A newer Command Line Tools release is available. Update them from Software Update in the App Store. Warning: You have unlinked kegs in your Cellar Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run `brew link` on these: libpng freetype glib webp unixodbc mysql pcre jpeg libzip Warning: Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in /usr/local/sbin. Consider setting the PATH for example like so echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile Warning: Your Xcode (9.3) is outdated. Please update to Xcode 9.4 (or delete it). Xcode can be updated from the App Store.
めっちゃ警告してきてます。
警告は計5つあるようです。
警告1つ目
Warning: The following directories are not writable: /usr/local/lib/pkgconfig This can happen if you "sudo make install" software that isn't managed by Homebrew. If a formula tries to write a file to this directory, the install will fail during the link step. You should change the ownership of these directories to your account. sudo chown -R $(whoami) /usr/local/lib/pkgconfig
/usr/local/lib/pkgconfigに書き込み権限が無いようです。
「sudo chown -R $(whoami) /usr/local/lib/pkgconfig」で解決できるとのこと。
エラーの解決方法を教えてくれるなんてHome brew優しすぎるぜ…!
$(whoami)は現在ログインしてるusernameにすれば良いです。
僕はここで少しハマりました。
$(whoami) == usernameなのか(whoami) == usernameなのかwhoami == usernameなのかが初見殺しすぎる…
(正解は$(whoami) == username)
警告2つ目
Warning: A newer Command Line Tools release is available. Update them from Software Update in the App Store.
書いてあるまま、App StoreでCommand Line Toolsを更新すれば解決できました。以上。
ソフトウェア自体をアップデートしても構わないみたいです。
エラーの解決方法を教えてくれるなんてHome brew優しs(ry
警告3つ目
Warning: You have unlinked kegs in your Cellar Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run `brew link` on these: libpng freetype glib webp unixodbc mysql pcre jpeg libzip
一部のツールがunlinkになっているとのこと。
こちらの警告も書いてあるまま、brew link (ツール名)でずらりと並んでいるツール名を下記のように片っ端から打ち込めば解決。
エr(ry
$ brew link libpng Linking /usr/local/Cellar/libpng/1.6.34... 18 symlinks created $ brew link freetype Linking /usr/local/Cellar/freetype/2.9.1... 8 symlinks created $ brew link glib Linking /usr/local/Cellar/glib/2.56.1... 146 symlinks created $ brew link webp Linking /usr/local/Cellar/webp/1.0.0... 26 symlinks created $ brew link unixodoc Error: No such keg: /usr/local/Cellar/unixodoc $ brew link unixobdc Error: No such keg: /usr/local/Cellar/unixobdc $ brew link unixodbc Linking /usr/local/Cellar/unixodbc/2.3.6... 37 symlinks created $ brew link pcre Linking /usr/local/Cellar/pcre/8.42... 133 symlinks created $ brew link jpeg Linking /usr/local/Cellar/jpeg/9c... 18 symlinks created $ brew link libzip Linking /usr/local/Cellar/libzip/1.5.1... 127 symlinks created
警告4つ目
Warning: Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in /usr/local/sbin. Consider setting the PATH for example like so echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
/usr/local/sbinにpathが通っていないようなので、
$ echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
でpathを通して、
$ source ~/.bash_profile
で変更を反映すればいいみたいです。
警告5つ目
Warning: Your Xcode (9.3) is outdated. Please update to Xcode 9.4 (or delete it). Xcode can be updated from the App Store.
Xcodeのバージョンが古いとのことなので、App StoreでアップデートすればOK。
Xcodeのアップデートに数十分かかったのにはビビりました。
全てのエラーの原因を解決した上で再び「brew doctor」を実行!
$ brew doctor Your system is ready to brew.
ということで警告は全て消え去りました。
スゲーッ爽やかな気分だぜ 新しいパンツをはいたばかりの正月元旦の朝のよーによォ~~~~~~~~~~ッ
これで少しはHome brewの扱いには少し慣れたような気がします。
Home brewのエラーは親切でありがたい限りです。
参考にしたサイト
brew doctorでのWarningを解決してみた(for Mac)
コマンドラインでbrew doctorすると警告だらけになっちゃった助けて
Homebrewのエラーを治す
フロントサイドのプログラムを触り始めてからの日常生活への影響
ここ1ヶ月ほどは研修でほぼずっとフロントサイド(HTML, CSS, jQuery)のプログラムを書いてました。
フロントサイドのことを学んだことによって、日常生活でWebサイトの見え方が前までと少し変わってしまったように感じます。
例をいくつか紹介していきたいと思います。
・レイアウトをこうした方がもっと使いやすくなるんじゃないかと考えてしまう。
(画面を遷移して表示するんじゃなくてモーダルで表示して画面を遷移をしない方が使いやすいんじゃないか等)
・CSSでどんなスタイルを指定しているのかを考えてしまう。
(この文章はtext:align: centerを使っているのかなとか、このボタンはbackground-colorで背景色を指定してcolorで文字の色も変えていてborder-radiusで角を丸くしているなとか)
・クリックしたらイベントが発生する時に連打するとどんな挙動をするのかを試してしまう。
(クリックしたら要素がスライドして見え隠れする時、連打したらクリックした回数見え隠れしてしまうのか等)
着々と技術力がついてきているんだなと感じる一方、これは職業病だなと感じ複雑な気分になります。
入社して3週間ちょっとの中で感じた1つのこと
今回は、入社してからまだ1ヶ月も経たない今日ですが、研修の中で感じたことをちょっと書いていきたいと思います。
システムエンジニアに関する研修の中で、見積書作成、UI設計、データベース設計を行いました。
当たり前ですがどれも未経験のことで大分頭を悩ませながら課題に取り組んでいました。
課題に取り組んでいる時に、あれはどうしたらいいこれはああした方がいいかと考えれば考えるほど、どんどん考えが膨れ上がっていって収拾がつかなくなる時もありました。
そんな中考える時は、どうすると相手が喜ぶのか、嬉しいのかを考えることが大事なんじゃないかと感じました。
見積書だと、お客さんが見ただけで理解しやすく納得できるような項目や説明になっているのかどうか。
UI設計だと、ユーザーが見ただけで使いやすいユーザーフレンドリーな設計であるかどうか。
データベース設計だと、ユーザーがデータベースを使う目的に必要な設計であるかどうか。
という視点が、もし自分がSEになって業務にあたっていく時に大切なことなんじゃないかなーと感じました。
ブログ始めました
初めまして、てつと申します。
このブログは一人前のエンジニアになるために、自分が学んだことについて書いていきます。
ブログという形で文章を書くのは久々ですが、読みやすい記事になるよう心がけていきたいです。
直近の目標は来年の3月までには「盾ッ!?」ボタンと「剣だッ!」ボタンを作れればなと思っています。(にゃんぱすーボタンみたいなの)
元ネタをご存知な方は一度お話してみたいです。
自分のスキルを磨いて、誰かを嬉しい気持ちにさせて、そうして自分も嬉しくなれるように頑張っていきたいと思います。
どうぞよろしくお願いします。