日期:2014-05-18  浏览次数:20602 次

一条查询语句,帮忙给看看问题出在哪了?
SELECT   DISTINCT   TagName,   COUNT(TagName)   AS   tagCount   FROM   Tag   WHERE   (AddUserID   =   65)   AND   (tagCount   >   1)   GROUP   BY   TagName   ORDER   BY   tagCount   DESC

执行后报错:列名   'tagCount '   无效。

怎么解决?

------解决方案--------------------
select TagName,tagCount from
(
SELECT DISTINCT TagName, COUNT(TagName) AS tagCount,AddUserID FROM Tag
GROUP BY TagName,AddUserID ORDER BY tagCount DESC
)a
WHERE (AddUserID = 65) AND (tagCount > 1)
------解决方案--------------------
SELECT DISTINCT
TagName,
COUNT(TagName) AS tagCount
FROM Tag
WHERE (AddUserID = 65)
GROUP BY TagName
having COUNT(TagName) > 1
ORDER BY tagCount DESC
------解决方案--------------------
select * from
(
SELECT DISTINCT TagName, COUNT(TagName) AS tagCount FROM Tag WHERE (AddUserID = 65) AND (tagCount > 1) GROUP BY TagName
) t
ORDER BY tagCount DESC