查询一个表用户对新增用户进行统计不能用not in 需要用exists

MySql 码拜 8年前 (2016-02-08) 1538次浏览
下面是用not in 实现的 ,需要修改为 exists实现 ,跪求高手帮忙解决!
SELECT COUNT(*) from order_info_ref as oif where oif.order_time>=”2016-03-02 00:01:00″ and oif.order_time<=”2016-03-02 23:59:59″ and oif.ca_user_id NOT in
(SELECT oi.ca_user_id from order_info_ref as oi where oi.order_time>=”2016-03-01 00:01:00″ and oi.order_time<=”2016-03-01 23:59:59″);
解决方案

40

SELECT COUNT(*) 
from order_info_ref as oif 
where oif.order_time>="2016-03-02 00:01:00" 
and oif.order_time<="2016-03-02 23:59:59" 
and not exists (select 1 from order_info_ref 
		where order_time>="2016-03-01 00:01:00"
		and order_time<="2016-03-01 23:59:59"
		and ca_user_id=oif.ca_user_id )

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明查询一个表用户对新增用户进行统计不能用not in 需要用exists
喜欢 (0)
[1034331897@qq.com]
分享 (0)