简体   繁体   English

错误代码:1052。字段列表中的“属性”列不明确

[英]Error Code: 1052. Column 'ATTRIBUTE' in field list is ambiguous

When I attempt to run the bellow section, I get the following error message.当我尝试运行波纹管部分时,我收到以下错误消息。 I am still new to SQL so I am guessing that the issue is relatively simple, making you experts cringe just a little bit.我对 SQL 还是新手,所以我猜这个问题相对简单,让你们专家有点畏缩。 Regardless, thank you so so much to anyone who replies.无论如何,非常感谢任何回复的人。

SELECT DRINKER, COUNT(RATING)
FROM DRINKERS LEFT JOIN LIKES
ON LIKES.DRINKER = DRINKERS.DRINKER
WHERE LIKES.RATING < 0
GROUP BY LIKES.DRINK
ORDER BY DRINK ASC;

I get the error:我得到错误:

19:17:07 SELECT DRINKER, COUNT(RATING) FROM DRINKERS LEFT JOIN LIKES ON LIKES.DRINKER = DRINKERS.DRINKER WHERE LIKES.RATING < 0 GROUP BY LIKES.DRINK ORDER BY DRINK ASC LIMIT 0, 1000 19:17:07 SELECT DRINKER, COUNT(RATING) FROM DRINKERS LEFT JOIN LIKES ON LIKES.DRINKER = DRINKERS.DRINKER WHERLIKES.RATING < 0 GROUP BY LIKES.DRINK ORDER BY DRINK ASC LIMIT 0, 1000

Error Code: 1052. Column 'DRINKER' in field list is ambiguous 0.00031 sec错误代码:1052。字段列表中的“DRINKER”列不明确 0.00031 秒

Thanks for any help at all!非常感谢您的帮助!

You should qualify all column references.您应该限定所有列引用。 Because you are using LEFT JOIN , I am guessing that you want all drinkers returned.因为您使用的是LEFT JOIN ,所以我猜您希望所有饮酒者都返回。 Your WHERE clause limits the result set to only those drinkers with negative ratings.您的WHERE子句将结果集限制为只有那些评分为负的饮酒者。

If you want all drinkers, then that condition needs to move to the ON clause.如果您想要所有饮酒者,则该条件需要移至ON子句。 I also recommend table aliases:我还推荐表别名:

SELECT D.DRINKER, COUNT(L.RATING)
FROM DRINKERS D LEFT JOIN
     LIKES L
     ON L.DRINKER = D.DRINKER AND
        L.RATING < 0
GROUP BY D.DRINKER
ORDER BY D.DRINKER ASC;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM