我如何按此查询分组,每个条目没有两列

How can I group by this query that there's not two columns per entry

我在灵活搜索中有这个查询:

SELECT
    {p.pk} AS PK,
    {year.code} AS year
FROM {Product AS p
    LEFT JOIN Year AS y ON {p.yearpk}={year.pk}
}
ORDER BY {p.pk} ASC

结果我得到:

PK    |    year
---------------
1     |    null
1     |    2016
2     |    null
2     |    2016

如何将这些多条记录分组为一条记录:

PK    |    year
---------------
1     |    2016
2     |    2016

我已经用 "GROUP BY {p.pk}" 试过了,但是查询并没有 returns 我上面提到的结果 - 相反它 returns 2 条记录但是年份是null 而不是 2016.

我该如何解决这个问题?

您需要将 left join 更改为 inner join。那应该可以解决您的问题。