在Linux中,不同的SQL无法与UNNEST一起使用 [英] IN Linux Distinct SQL is not working with UNNEST

查看:88
本文介绍了在Linux中,不同的SQL无法与UNNEST一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在窗口系统中运行此查询时,行为正确UNNSET
但当我运行此查询时,Linux行为不同.unnset不同行上的重复记录列表

When i run this query in window system behave correctly UNNSET but when i run this query Linux behave different.unnset duplicate record list on different row

SELECT DISTINCT 
         "billing_billmanagement"."creation_date",
         "billing_billmanagement"."bill_number",
         unnest(array_agg(DISTINCT "inventory_product"."product_name")) AS "product",
         unnest(array_agg(DISTINCT "services_service"."name")) AS "service"
FROM "billing_billmanagement"
  INNER JOIN "users_staffuser" ON ("billing_billmanagement"."staff_id" = "users_staffuser"."id")
  INNER JOIN "auth_user" ON ("users_staffuser"."user_id" = "auth_user"."id")
  LEFT OUTER JOIN "billing_customerproductbill" ON ("billing_billmanagement"."id" = "billing_customerproductbill"."bill_id")
  LEFT OUTER JOIN "inventory_product" ON ("billing_customerproductbill"."product_id" = "inventory_product"."id")
  LEFT OUTER JOIN "billing_customerservicebill" ON ("billing_billmanagement"."id" = "billing_customerservicebill"."bill_id")
  LEFT OUTER JOIN "services_service" ON ("billing_customerservicebill"."service_id" = "services_service"."id")

WHERE "billing_billmanagement"."creation_date" BETWEEN '2017-12-04' AND '2017-12-06'
GROUP BY billing_billmanagement.creation_date,
         billing_billmanagement.bill_number
ORDER BY "billing_billmanagement"."creation_date" ASC


推荐答案

如果问题出在重复行,请尝试

If getting duplicate rows is the problem, try this

 SELECT billing_billmanagement.creation_date,
           billing_billmanagement.bill_number,
           inventory_product.product_name AS product,
           services_service.name AS service
    FROM billing_billmanagement
      INNER JOIN users_staffuser ON (billing_billmanagement.staff_id = users_staffuser.id)
      INNER JOIN auth_user ON (users_staffuser.user_id = auth_user.id)
      LEFT OUTER JOIN billing_customerproductbill ON (billing_billmanagement.id = billing_customerproductbill.bill_id)
      LEFT OUTER JOIN inventory_product ON (billing_customerproductbill.product_id = inventory_product.id)
      LEFT OUTER JOIN billing_customerservicebill ON (billing_billmanagement.id = billing_customerservicebill.bill_id)
      LEFT OUTER JOIN services_service ON (billing_customerservicebill.service_id = services_service.id)
    WHERE billing_billmanagement.creation_date BETWEEN '2017-12-04' AND '2017-12-06'
    GROUP BY 1,
             2,
             3,
             4
    ORDER BY 1 ASC;

这篇关于在Linux中,不同的SQL无法与UNNEST一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆