带有 Group By 的Where子句

发布于 2024-12-03 22:44:51 字数 592 浏览 0 评论 0原文

我有一个这样的查询:

SELECT TPCombined.Title, 
GROUP_CONCAT(DISTINCT CONCAT(a.LastName, ', ', a.FirstName) SEPARATOR '<br />') as Author 
FROM ((SELECT b.Title FROM BookList b) UNION (SELECT s.Title FROM Studios s)) 
AS TPCombined 
LEFT OUTER JOIN (AuthorLinks al JOIN Authors a ON al.AuthorStem = a.AuthorStem) 
ON TPCombined.BookStem = al.BookStem 
WHERE Author LIKE '%Smith%' GROUP BY BookStem; 

此查询不起作用:

“where 子句”中存在未知列“作者”

这适用于 HAVING 而不是 WHERE。但我确实需要使用Where。请您确认这是否真的不可能?或者也许我可以以某种方式修复查询以使其与Where? 一起使用?

I have a query like this:

SELECT TPCombined.Title, 
GROUP_CONCAT(DISTINCT CONCAT(a.LastName, ', ', a.FirstName) SEPARATOR '<br />') as Author 
FROM ((SELECT b.Title FROM BookList b) UNION (SELECT s.Title FROM Studios s)) 
AS TPCombined 
LEFT OUTER JOIN (AuthorLinks al JOIN Authors a ON al.AuthorStem = a.AuthorStem) 
ON TPCombined.BookStem = al.BookStem 
WHERE Author LIKE '%Smith%' GROUP BY BookStem; 

This query doesn't work:

Unknown column 'Author' in 'where clause'

This would work with HAVING instead of WHERE. But I really need to use Where. Could you please confirm if this is really impossible? Or maybe I can fix the query somehow to make it work with Where?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鲜血染红嫁衣 2024-12-10 22:44:51

WHERE 子句应用于行级别。您已将聚合函数别名为 Author,这意味着它的结果在行级别不可用 - 仅当查询完成并准备好发送给客户端时。您需要使用 HAVING 过滤器,该过滤器在发送到客户端之前应用。

WHERE clauses are applied at the row level. You've aliased an aggregate function as Author, which means its results won't be available at the row level - only when the query is complete and ready to go to the client. You'd need to use a HAVING filter instead, which is applied just before sending to client.

半夏半凉 2024-12-10 22:44:51

您需要使用前缀 TPCombined ... TPCombined.Author LIKE ... 来限定作者

you need to qualify Author with prefix TPCombined ... TPCombined.Author LIKE ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文