MySQL:没有像组中那样的字符串?
我的表中有两列:VisitorID 和 URL。
对于访问者进行的每个页面视图,表中都存在一个条目。我想查看每个访问者的总访问次数,其中访问者组中没有一个 URL 类似于“%page=checkout%”。
我想它是这样的:
SELECT *, COUNT(*) AS TotalVisits FROM `VisitorLog` GROUP BY VisitorID HAVING `URL` NOT IN (SELECT * FROM ?? WHERE `URL` LIKE "%page=checkout%")
但我不完全理解 HAVING 子句如何与子查询一起使用,如果我需要子查询,等等?又如何让自己变得消极呢?
任何能解释答案的人都会得到奖励积分,这样我下次就可以自己做!
谢谢,
尼克
I have two columns in a table: VisitorID, and URL.
An entry exists in the table for every page view a visitor makes. I'd like to see the total number of visits for each Visitor, where NONE of the URLs in a visitor's group are LIKE "%page=checkout%".
I'm thinking it's something like this:
SELECT *, COUNT(*) AS TotalVisits FROM `VisitorLog` GROUP BY VisitorID HAVING `URL` NOT IN (SELECT * FROM ?? WHERE `URL` LIKE "%page=checkout%")
But I don't entirely understand how the HAVING clause works with a sub-query, if I need a sub-query at all, etc? And how to make having negative?
And bonus points for anyone who can explain the answer so that I can do it myself next time!
Thanks,
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您的
visitorLog
表中的URL
字段是foreign_key 和整数字段。据我了解,例如。
为什么需要使用
having
,因为聚合函数不能在WHERE
中使用http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
你也可以 这样写的
下面是
,如有错误,请大家指正。
谢谢。
I assume your
URL
field invisitorLog
table is foreign_key and integer field.As from my understanding,eg.
Why you need to use
having
, because aggregate function can't be use inWHERE
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
You can also write like this
Below is wrong
Any one please correct me if I am wrong.
Thanks.