【SQL】内部の処理順序([SQL] internal processing order)

SQLの実行句は上から順、基礎の基礎。将棋の駒みたいに各句の場所と強さがあって、プログラム言語って、ほんと外国語みたい…あくまで命令なので単語は少ないけど文法はある。

外国語と違うのはスペルミスに容赦ないところ。人みたいに補完してくれない…機械だもの。AIだって参考元はほかのデータ達です。前に誰かが同じ間違いしてたら教えてくれるんだろうけどね。ネタ元が膨大すぎて傍目万能に見えるけれど、精査も結局はプログラムです。正しいかの判断をAIに委ねず、情報に振り回されず共存出来たらいいなあ。


SQL書き順

  1. SELECT(カラム)
  2. FROM(データベース)
  3. WHERE(データ絞り込み)
  4. GROUP BY(グループ化)
  5. HAVING(WHEREに似てるやつ)
  6. ORDER BY(並び順)
  7. LIMIT(取得件数)

実行順序は1.SELECTが5.HAVINGの後に来る。それは納得。WHEREは偉い(言い方)のでGROUPの後ろだとエラー、HAVING使う。SELECTにはIF,CASE,MAXMIN,COUNTはいる。FROMにはJOINはいる、コマンド用途の違い。

SQLにはRみたいにhead一覧取得するコマンドあるのかな?データ扱う時って全属性を把握しとかなきゃと意気込むんですが、BigQueryのスキームだといまいち頭に入ってこない。慣れか。そうか。学び足りないのか。


プログラムの書き方は人それぞれで、目標は他人が見ても理解できる書き方をしたい。前職でhtml&cssを使っていた時、雑な書き方で同僚を困らせていたことを思い出しました。

今になって思えば、独学で自己満の書き方=ページが構成されればいい、くらいの理解力しかなかったんだなと反省しています。優秀なプログラムは見た目もきれいなんですよね。私はせいぜいコメントアウトで補足して周りに理解を求めてました。わー自己中。

特集ページを必死で作っても、プロではないから当たり障りないコマンドの重ね合わせで分量が増えて、自分ですら後で見返しても読み解きに時間がかかってました。その業務だけに入り込んでるときはいいんですけど、終わったら忘れちゃうという。説明できても平易に書き直す気力は残ってなかった。元同僚の皆ごめんなさい。


子どもニュースのお父さん(世代ばれる)が「本当に賢い人は、平易な言葉で説明できる」と言っていた。身に沁みます。そうなりたいです。


********


The SQL execution clauses are top-down. Like shogi pieces, each word has its place and its strength, and programming languages are really like foreign languages... Because they are commands, they have fewer words than languages, but they have grammar.

Unlike foreign languages, there is no mercy for spelling mistakes. It doesn't complement like a human... because it's a machine.

Even AI is based on other data. So if someone has made the same mistake before, it'll let me know.

There are so many sources of data that it is big, everywhere, but verification is also a programme. It would be nice if we could coexist without being influenced by information, without make the judgement of bias.


SQL writing order

  1. SELECT (column)
  2. FROM (Database)
  3. WHERE (data filtering)
  4. GROUP BY (summary)
  5. HAVING (similar to WHERE)
  6. ORDER BY (arrangement)
  7. LIMIT (number of acquisitions)

The order of execution is 1.SELECT after 5.HAVING. I see. Error if WHERE comes after GROUP, use HAVING. SELECT contains IF, CASE, MAXMIN and COUNT. There is a JOIN in FROM, the difference in command usage.

Does SQL have a command to get the header list like R? When dealing with data, I'm enthusiastic about understanding all the attributes, but with BigQuery's schema, it doesn't come to mind. I'm not learning enough...


Everyone writes programs differently and my aim is to write in a way that others can understand. When I was using html & css at my previous job, I remember that my colleagues were annoyed by my rough writing style.

I regret that the only way I could learn to write was by studying on my own. An excellent programme looks good.

When I was desperately trying to create an HTML page, even though I'm not a professional, the volume increased by superimposing commands that were monotonous. What's more, it's fine when I'm immersed in the task, but when it's over I forget about it. Even if I could explain it, I wouldn't have the energy to rewrite it. I apologise to all my former colleagues.


On the educational TV programme "Children's News" they said:

" A really clever person can explain things in plain language. "

I think that is true. I want to be.