没有消费的用户的详细信息Select * From tb_userinfo u Where Not Exists (Select m.Id form mingxi m Where m.Id = u.Id And .....)--其它条件 然后根据用户id找最大的日期,可能会用到子查询,有没有效率更高点的?
select a.m_id ,min(b.deal_date) from tb_userinfo a left out join tb_mingxi b on a.m_id = b.m_id where b.deal_date < $statis_date group by a.m_id 这样行吗?
select A.*, B.max_date from tb_userinfo A inner join ( select m_id,max(date) as max_date from tb_mingxi where date < 指定日期 group by m_id, date ) B on A与B的关联条件
刚才发错了:select A.*, B.max_date from tb_userinfo A inner join ( select m_id,max(date) as max_date from tb_mingxi C where date < 指定日期 and not exists (select 1 from tb_mingxi where m_id = C.m_id and date = 指定日期) group by m_id, date ) B on A与B的关联条件
Where Not Exists (Select m.Id form mingxi m
Where m.Id = u.Id
And .....)--其它条件
然后根据用户id找最大的日期,可能会用到子查询,有没有效率更高点的?
a.m_id
,min(b.deal_date)
from tb_userinfo a
left out join tb_mingxi b
on a.m_id = b.m_id
where b.deal_date < $statis_date
group by
a.m_id
这样行吗?
from tb_userinfo A
inner join (
select m_id,max(date) as max_date from tb_mingxi
where date < 指定日期
group by m_id, date
) B
on A与B的关联条件
from tb_userinfo A
inner join (
select m_id,max(date) as max_date from tb_mingxi C
where date < 指定日期 and not exists (select 1 from tb_mingxi where m_id = C.m_id and date = 指定日期)
group by m_id, date
) B
on A与B的关联条件