我在 PostgreSQL 中有以下查询:
SELECT sale_order.id,sale_order.name AS orden, now()::date AS hoy,
sale_order.create_date::date, split_part(res_partner.name,' ',1) AS cliente,
res_partner.email,sale_order.amount_total,res_currency.name FROM
sale_order,product_pricelist,res_currency,res_partner WHERE
sale_order.partner_id = res_partner.id
AND sale_order.pricelist_id = product_pricelist.id
AND product_pricelist.currency_id = res_currency.id
AND sale_order.state = 'sent'
ORDER BY sale_order.create_date DESC;
结果集如下所示:
658, SO658, 2015-05-17, 2015-04-16, Alejandro, [email protected] /cdn-cgi/l/email-protection, 14272.00, MXN
654, SO654, 2015-05-17, 2015-04-15, Edgar, [email protected] /cdn-cgi/l/email-protection, 4994.96, MXN
653, SO653, 2015-05-17, 2015-04-15, Edgar, [email protected] /cdn-cgi/l/email-protection, 3007.29, USD
正如您所看到的,第二条和第三条记录在某种程度上是重复的,因为它是同一用户,但具有不同的 ID、订单名称、日期等。
我想要做的是忽略日期和金额,但 GROUP_CONCAT 订单名称,所以最终结果将如下所示:
SO658, Alejandro, [email protected] /cdn-cgi/l/email-protection
SO653 & SO654, Edgar, [email protected] /cdn-cgi/l/email-protection
正如您所看到的,我删除了不必要的列和 GROUP_CONCAT 属于同一用户的订单名称,因此最终每个用户只有一条记录显示其所有订单名称。
我怎样才能在 PostgreSQL 中做到这一点?
谢谢你!