【问题标题】:How can I group by this query that there's not two columns per entry如何按此查询分组,每个条目没有两列
【发布时间】:2016-07-13 13:25:48
【问题描述】:

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

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}”,但是查询没有返回我上面提到的结果——而是返回 2 条记录,但年份为空,而不是 2016 年。

我该如何解决这个问题?

【问题讨论】:

  • SELECT {p.pk}, {year.code} FROM {Product as p},{Year as year} where {p.yearpk}={year.pk} ORDER BY {p.pk} ASC

标签: sql hybris


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    相关资源
    最近更新 更多