【发布时间】:2016-04-30 21:30:04
【问题描述】:
我试图使我的列等于过滤器使用有,但问题是它给出了这个错误消息:
column is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY
当我尝试在 select 和 group by 中添加过滤器时,它会说:
Column names in each view or function must be unique
因为列和过滤器都是一样的:
专栏:
userTable.userid
过滤器:
user_filter.userid
这是我的代码:
SELECT DISTINCT
userId,
username,
sum(userItem)
from userTable inner join user_filter
on userTable.userName = user_filter.userName
group by userId,
username,
having userTable.userId = user_filter.userId
【问题讨论】:
-
编辑您的问题并包含生成错误的查询。
-
好的,我会添加查询
-
你真正想要达到什么目的?当两个表都有
userid时,你为什么要通过username加入?当username已经在usertable中时,为什么userfilter 仍然有username? -
您使用的是什么 DBMS? MySQL、SQL Server、PostgreSQL、...?