0
1

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 1 year has passed since last update.

カンマ区切りの文字列からテーブルを作成する方法

Posted at

カンマ区切りの文字列からテーブルを生成し、
以下のデータから対象のIDのレコードを取得する方法を説明します。

image.png

コーディング例

WITH 対象ID AS (
	SELECT value AS ID FROM 
    string_split('0000000003,0000000004,0000000006', ',')
)

SELECT * FROM 商品マスタ 
INNER JOIN 対象ID ON ID = 商品ID

結果

商品IDが0000000003と0000000004と0000000006のレコードを取得できました。
image.png

ポイント

:pencil2: STRING_SPLITは第一引数の文字列を、第二引数で指定した区切り文字で分割して、結果をテーブルとして返却する関数です。
STRING_SPLIT([文字列], [区切り文字])

:pencil2: WITH句を使用して、クエリ内でテーブルを新たに生成するこができます。
WITH [作りたいテーブル名] AS ([作成したいテーブルを作るクエリ])

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?