+ -
当前位置:首页 → 问答吧 → 急,mysql中NOT IN的问题

急,mysql中NOT IN的问题

时间:2011-10-21

来源:互联网

RT,SQL code
select * from data_players where from_unixtime(last_login,"%Y-%m-%d")="2011-10-18" and from_unixtime(reg_time,"%Y-%m-%d")="2011-10-18" and sex=1 and reg_site_no="5"

查出684条结果
SQL code
select pid from data_players where from_unixtime(last_login,"%Y-%m-%d")="2011-10-19" and sex=1 and reg_site_no=5

查出370条结果
SQL code
select * from data_players where from_unixtime(last_login,"%Y-%m-%d")="2011-10-18" and from_unixtime(reg_time,"%Y-%m-%d")="2011-10-18" and sex=1 and reg_site_no="5" and (pid not in(select pid from data_players where from_unixtime(last_login,"%Y-%m-%d")="2011-10-19" and sex=1 and reg_site_no=5))

仍然是684条结果,请问是NOT IN没起作用么?

作者: hxm19881010   发布时间: 2011-10-21

先看下你的第一条查询的684条记录与第一条查询的370条记录有没有相同的pid,如果没有,那就是正确的。。

作者: ohmygirl   发布时间: 2011-10-21

from_unixtime(last_login,"%Y-%m-%d")="2011-10-18"

本来就 not in

from_unixtime(last_login,"%Y-%m-%d")="2011-10-19" 
,,


你的语句,还是直接用时间戳比较好,,,如有索引可避免扫全表

作者: amani11   发布时间: 2011-10-21

引用 2 楼 amani11 的回复:

from_unixtime(last_login,"%Y-%m-%d")="2011-10-18"

本来就 not in

from_unixtime(last_login,"%Y-%m-%d")="2011-10-19"
,,


你的语句,还是直接用时间戳比较好,,,如有索引可避免扫全表


虽然时间不一样,但也不一定pid就没有重合的吧,除非是主键。。

作者: ohmygirl   发布时间: 2011-10-21