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.

[PostgreSQL] 学んだことまとめ

Posted at

配列で入っているカラム

カウント

# select array_length(requests.request_items) from requests;

結合

# select array_cat(requests.request_items, request.answer_items) from requests;

中身によってカウントするか決める

# select (SELECT SUM(CASE item WHEN 'email' THEN 1 ELSE 0 END) FROM unnest(company_worker_profile_requests.request_profile_groups) AS dt(item)) from requests;

率計算

# WITH numbers AS (SELECT 500 AS 分母, 400 AS 分子)
SELECT trunc(CAST(分子 AS FLOAT) / CAST(分母 AS FLOAT)*100) || '%' FROM numbers;

-- 80%

withはセミコロンつけるとリレーション効かなくなるのでつけない。
基本的にダブルクオテーションは使用しない(カラム認識されてしまう時がある)

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?