我有兩個表標記和使用者PostgreSQL的JOIN與陣列型與數組元素
表名稱:標籤
| id | name |
| 1 | one |
| 2 | two |
| 3 | three |
| 4 | four |
| 5 | five |
表名:用戶
| id | fname | tags |
| 1 | Ram | {1,5} |
| 2 | Sham | {1,2,3,4} |
| 3 | Bham | {1,3} |
| 4 | Kam | {5,2} |
| 5 | Lam | {4,2} |
預期輸出:
| id | fname | tags |
| 1 | Ram | one, five |
| 2 | Sham | one, two, three, four |
| 3 | Bham | one, three |
| 4 | Kam | five, two |
| 5 | Lam | four, two |
試用1:使用JOI ñ
SELECT I.id, I.fname, I.tags, J.name FROM users I
JOIN tags J ON J.id = ANY(I.cached_tag_ids)
LIMIT 1
結果:
| id | fname | tags |
| 1 | Ram | one |
| 1 | Ram | five |
預計:
| id | fname | tags |
| 1 | Ram | one, five |
第一行中不要你的意思是一,五 – Mihai 2014-10-29 18:41:15
是的,對不起我的錯誤 – 2014-10-29 18:57:50