表格:lead_salesperson

------------------------
id    | sp_id   |  phone
------------------------
0     | 1       |  12345678
1     | 1       |  87654321


表:productProperties

------------------------------------------------
product  | sp_id    |  phone    | activity_name
------------------------------------------------
0        | 1        |  12345678 | vm
1        | 1        |  12345678 | DNC
2        | 1        |  87654321 | SCB
3        | 1        |  77654321 | SCB




Select DISTINCT(l.phone) as phone
  from lead_salesperson as l
  join lead_activity as ls
  on (ls.phone=l.phone) && (ls.year_make=l.year_make) && (ls.make=l.make)
 where l.sp_id=$sp_id and ((ls.act_name!='DNC') OR (ls.act_name!='DNC_AUTO'))


因此输出应为87654321,77654321

我正在尝试获取所有没有DNC或DNC_AUTO的电话号码... Leadactivity可以将多行连接到lead_salesperson中的一行。如果即使其中一行(电话)在activity_name中具有DNC或DNC _AUTO,那么我也不希望该电话成为结果集的一部分,请提出任何想法...如何解决此问题。

最佳答案

我认为您可以通过定义要排除的电话的子查询来解决此问题:

select distinct phone
from lead_activity as ls
where act_name in ('DNC', 'DNC_AUTO')


现在,您可以将此查询用作条件:

select distinct
    l.phone as phone
from
    lead_salesperson as l
where
    phone not in (
        select distinct phone
        from lead_activity as ls
        where act_name in ('DNC', 'DNC_AUTO'))


希望这对您有帮助

关于mysql - mysql之一是很多rquery,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13191131/

10-12 19:03