[英]mysql one is to many rquery
table: lead_salesperson 表格:lead_salesperson
------------------------
id | sp_id | phone
------------------------
0 | 1 | 12345678
1 | 1 | 87654321
table: productProperties 表: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'))
so the output should be 87654321,77654321
所以输出应该是
87654321,77654321
I am trying to get all phone numbers that do not have a DNC or DNC_AUTO ... the leadactivity has can have multi rows connected to one row in lead_salesperson . 我正在尝试获取所有没有DNC或DNC_AUTO的电话号码... Leadactivity可以将多行连接到lead_salesperson中的一行。 IF even one of the rows (phone) has a DNC or DNC _AUTO in the activity_name then i do not want that phone to be part of the result set any ideas...how to solve this.
如果即使其中一行(电话)在activity_name中具有DNC或DNC _AUTO,那么我也不希望该电话成为结果集的一部分,请提出任何想法...如何解决此问题。
I think you can solve this with a subquery that defines the phones that you want to exclude: 我认为您可以通过定义要排除的电话的子查询来解决此问题:
select distinct phone
from lead_activity as ls
where act_name in ('DNC', 'DNC_AUTO')
Now, you can use this query as a condition: 现在,您可以将此查询用作条件:
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'))
Hope this helps you 希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.