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?

4月に読んだ記事

Last updated at Posted at 2024-04-10

10日 COUNTの「OR NULL」について

COUNT(条件式)とした場合、条件式部分の返却値は1又は0となり、COUNT(条件式)のCOUNTは0も数えるため取得件数が想定より増えてしまう(というより、条件式を使っている意味がなくなる)。
COUNT(条件式 OR NULL)とすると、条件式の結果が0のとき(条件式 OR NULL)はNULLを返す。COUNTはNULLを数えないため、条件式に当てはまるレコードのみCOUNT出来るってわけ。
※ここでの条件式は、カラムの値に対して演算子を用いたもの。例)year > 5

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?