0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SQLハック

Last updated at Posted at 2020-12-07

SQLハックとは

たかがSQL されどSQL 実務で通用することを狙ってのページです。

SQL

MySQLを想定しています。圧倒的に業務ではOracleだったのでOracleについての言及していることもあります。

モチベーション

喜びをもって道を切り開く。
SQL is an extremely in demand skill. Tons of jobs use SQL
NEXT STEP NEXT STEP
SQL獲得は素晴らしいスキルをあなたは手に入れるということです。

前提知識

・Progateの道場コース以外は完了しておくこと。

参考図書等

・[データベースの気持ちがわかる]SQLはじめの一歩 WEB+DB PRESS plus
https://www.amazon.co.jp/dp/B07JHJDTVX/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1

・SQL 第2版 ゼロからはじめるデータベース操作
https://www.amazon.co.jp/dp/B01HD5VWWO/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1

・SQL for Data Analysis Udacityで部分的に学ぶ。

コンテンツ

・用語
・シラバス
・TAKEAWAY

シラバス

select * from a_table;
SELECT id, name FROM a_table;
select * from a_table where a <> 0 AND b <> 0;
select * from a_table where no = 1 OR no = 2;
select a from b where ( or ) and (( or ) and )
 ← or より andが強いため()で括る必要がある。
limit
order by
name NOT LIKE 'A%' AND name LIKE '%d';
xxdate BETWEEN '2016-01-01' AND '2017-01-01'
select * from a_table where text like '%SQL';
select * from a_table where text like 'SQL%';
select * from a_table where text like '%SQL%';
select * from a_table where text like '%¥%%';
is NULL
is NOT NULL
Select a AS "コード" ,
CASE
when a = 1 then '男'
when a = 2 then '女'
else '未定義'
End as "性別" From a_table;
SELECT COUNT(*) FROM accounts;

SELECT COUNT(id) FROM accounts;
← NULLは数えない。

TAKEAWAY

日付の型

Oracle
https://qiita.com/ponsuke0531/items/57bc035f129922b1b0de
注 日付の型がきちんとしていないとINSERTできない。できても問題が・・・

0割回避

A few accounts have 0 for total, so I divided by (total + 0.01)

GROUP BY

Any column in the SELECT statement that is not within an aggregator must be in the GROUP BY clause.

The GROUP BY always goes between WHERE and ORDER BY.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?