我有 2 张桌子。TableA
是销售额,TableB
是潜在客户表。我正在尝试查看潜在客户中的人是否TableB
进行了购买,并且他们的名字是否出现在销售TableA
中。如果他们这样做,我只想要出现在两张桌子上的人的名字。
表A(销售)
customer school email address state phone Sales
john doe hight middle [email protected] 111 updown wi 2222222 $500
john doe hight middle [email protected] 111 updown wi 2222222 $100
zow hi hight middle [email protected] 111 updown wi 2222222 $200
calispo dwight elem [email protected] 34 jimm elis CA 35450456 $1,000
Jordan clift high [email protected] 1 unversity GA 11111111 $100
表 B(导联)
customer school email address state
john doe hight middle [email protected] 111 updown wi
Kawi hight middle [email protected] 111 updown wi
calispo dwight elem [email protected] 34 jimm elis CA
我想看到的:
customer school email address state
john doe hight middle [email protected] 111 updown wi 2222222 $500
alispo dwight elem [email protected] 34 jimm elis CA 35450456 $1,000
我尝试了这个查询,但它返回了我想要的信息的副本
SELECT a.email as [sales_school]
,b.email[leadds_insti]
,a.*
,b.*
FROM [dbo].[Sales] a
right JOIN leads b ON a.email= b.email
您可以尝试为每封电子邮件找到最高销售额,然后将其与潜在客户一起加入:
如果您只想要销售表中的潜在客户名称,那么应该这样做