2
4

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 5 years have passed since last update.

標準SQL書式のかんたんな一覧

Last updated at Posted at 2017-06-04

基本

select
	[{distinct|all}]{*| [,]}
from
	TABLE_NAME
[where ]
[group by COLUMN_NAME [{asc|desc}]]
[having ]
[order by COLUMN_NAME [{asc|desc}]]

順番は変更不可!!

凡例

  • [A]:オプション。Aはあってもなくてもいい
  • {A|B}:選択。AかBのいずれか
  • θ:比較演算。{<|<=|=|>=|>|<>}
  • TABLE_NAME :表名
  • COLUMN_NAME :列名

★ → 値式(列名か関数か式か定数)

関数 → 下記参照
式 → 演算式(*100とか+1とか)
定数 → 3.14とか365とか固定の値

▲ → 条件

下記をひとつ、またはand, or, not でつないで複数指定

  • 比較: ★ θ ★
  • BETWEEN: ★ [not] between ★ and ★
  • IN: ★ [not] in (★ [,★])
  • LIKE: COLUMN_NAME [not] like "なんらかの文字列"
  • NULL: COLUMN_NAME is [not] null

関数(countとか)

  • 総数 count: count([{distinct|all}] {COLUMN_NAME|*})
  • 総和 sum:sum([{distinct|all}] COLUMN_NAME)
  • 平均値 avg:avg([{distinct|all}] COLUMN_NAME)
  • 最大値 max:max(COLUMN_NAME)
  • 最小値 min:min(COLUMN_NAME)

サブクエリ用の記述

  • 比較: ★ θ (サブクエリ)
  • IN: ★ [not] in(サブクエリ)
  • 限定: ★ θ {all|any|some} (サブクエリ)
  • EXISTS: ★ exists (サブクエリ)

参考文献

  • 「リレーショナルデータベースの実践的基礎」速水治夫 著
2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?