简体   繁体   中英

MYSQL SELECT rows not in query

I have a statistics database for people who have visited. This table contains ID, timestamp IPv4, IPv6, User Agent and REQUEST_URI. I get false numbers by running something like

SELECT COUNT(DISTINCT IPv4) AS 'Uniques', COUNT(*) AS 'Total' FROM statistics

So I need to filter out the bots from humans. My approach is this:

SELECT ID FROM statistics WHERE NOT EXISTS(SELECT ID FROM statistics WHERE useragent NOT LIKE '%bot%')

This should select all rows from statistics which are not present in the query which searches for non-bots. I think the query looks reasonable so why isn't it working?

And there is a reason I want to do it this way instead of

SELECT ID FROM statistics WHERE useragent LIKE '%bot%'

Any ideas?

I'm a bit confused, but maybe you want to do:

SELECT ID FROM statistics 
WHERE ID NOT IN (SELECT ID FROM statistics WHERE useragent NOT LIKE '%bot%')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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