没有聚合函数的sql组

时间:2014-11-04 07:15:23

标签: sql postgresql group-by

我有这个由应用程序生成的查询。它没有抛出任何错误。我想知道group by子句如何在没有任何聚合函数的情况下工作。有人可以放心。

SELECT customer.id AS customer_id,
   customer.firstname AS customer_firstname,
   customer.lastname AS customer_lastname,
   customer.skype_id AS customer_skype_id,
   customer.phone AS customer_phone,
   customer.punch_line AS customer_punch_line,       
FROM customer
JOIN accounts ON accounts.id = customer.id
LEFT OUTER JOIN customer_skills ON customer.id = customer_skills.customer_id
LEFT OUTER JOIN skills ON skills.id = customer_skills.skill_id
WHERE accounts.activated_at IS NOT NULL
  AND accounts.published_at IS NOT NULL
  AND (EXISTS
     (SELECT 1
      FROM customer_skills
      WHERE customer.id = customer_skills.customer_id
        AND skills.title IN (:title_1,
                             :title_2)))
GROUP BY customer.id,
     accounts.id
ORDER BY accounts.registered_at DESC

0 个答案:

没有答案