假设我有以下表格:
table: followers_arrays
id | array
--------+---------
1 | {3,4,5}
table: small_profiles
id | username | pic
--------+----------+-------
3 | aaaa | abcd
4 | bbbb | abcd
5 | cccc | abcd
Run Code Online (Sandbox Code Playgroud)
我想打印followers_array与填充的数据来自small_profiles使用简单连接。
首先,我使用这样的unnest函数:
SELECT id, unnest(followers_array) AS elem FROM followers_arrays
Run Code Online (Sandbox Code Playgroud)
它给了我正确的结果:
id | elem
--------+--------
1 | 3
1 | 4
1 | 5
Run Code Online (Sandbox Code Playgroud)
现在,从我的理解我只需要这个数据加盟small_profiles ON small_profiles.id这样的关键:
SELECT id, unnest(followers_array) AS elem
FROM followers_arrays
JOIN small_profiles ON small_profiles.instagram_id = elem …Run Code Online (Sandbox Code Playgroud)