【发布时间】:2020-11-23 22:59:08
【问题描述】:
我正在使用 Postgres,我有以下方案。
订单
| id | status |
|----|-------------|
| 1 | delivered |
| 2 | recollected |
评论
| id | text | user | order |
|----|---------|------|-------|
| 1 | texto 1 | 10 | 20 |
| 2 | texto 2 | 20 | 20 |
所以,在这种情况下,一个订单可以有多个 cmets。
我需要遍历订单并得到类似的东西:
| id | status | comments |
|----|-------------|----------------|
| 1 | delivered | text 1, text 2 |
| 2 | recollected | |
我尝试使用 LEFT JOIN 但它不起作用
SELECT
Order.id,
Order.status,
"Comment".text
FROM "Order"
LEFT JOIN "Comment" ON Order.id = "Comment"."order"
它返回这个:
| id | status | text |
|----|-------------|--------|
| 1 | delivered | text 1 |
| 1 | delivered | text 2 |
| 2 | recollected| |
【问题讨论】:
标签: sql string postgresql subquery string-aggregation