【发布时间】:2010-04-15 17:23:21
【问题描述】:
这是一个由 Doctrine ORM 的 Taggable 扩展自动生成的查询。
SELECT t.id AS t__id, t.name AS t__name, COUNT(DISTINCT i.id) AS i__0,
(COUNT(DISTINCT i.id)) AS i__1
FROM taggable_tag t
LEFT JOIN cms__model__image_taggable_tag c ON (t.id = c.tag_id)
LEFT JOIN image i ON i.id = c.id
WHERE t.id IN
(SELECT doctrine_subquery_alias.id
FROM
(SELECT DISTINCT t2.id, (COUNT(DISTINCT i2.id)) AS i2__1
FROM taggable_tag t2
LEFT JOIN cms__model__image_taggable_tag c2 ON (t2.id = c2.tag_id)
LEFT JOIN image i2 ON i2.id = c2.id
GROUP BY t2.id HAVING i2__1 > 0
ORDER BY i2__1 DESC LIMIT 10) AS doctrine_subquery_alias)
GROUP BY t.id HAVING i__1 > 0
ORDER BY i__1 DESC
它在使用 MySql 时有效,但不适用于 PostgreSql。
我得到:column i2__1 not found 或 column i__2 not found。
使用 COUNT(DISTINCT) 时是否不允许使用别名?
这个查询在 PostgreSql 上应该如何工作?
【问题讨论】:
标签: mysql zend-framework postgresql doctrine portability