group by by bigquery标准sql并且无法获得唯一记录

时间:2018-03-27 06:15:21

标签: sql google-bigquery bigdata

在"组中获取错误错误:SELECT列表表达式引用列id_coupon既不是分组也不是聚合在... "

在我的表格中#34; table_name" id_coupon为每个id_discount都有多个条目。意味着id_discount不是唯一的,id_coupon是唯一的。我想只针对每个id_discount获得一个id_coupon ...

SELECT
  id_discount,
  id_coupon
FROM
  abbccc.discounts.table_name
  GROUP BY id_discount

1 个答案:

答案 0 :(得分:3)

SELECT
  id_discount,
  MIN(id_coupon) as id_coupon
FROM abbccc.discounts.table_name
GROUP BY id_discount