【发布时间】:2015-09-11 11:38:51
【问题描述】:
+--------------+--------------+------------+
| company_name | address_type | address |
+--------------+--------------+------------+
| Company A | Billing | 111 Street |
| Company A | Shipping | 111 Street |
| Company B | Billing | 222 Street |
| Company B | Shipping | 333 street |
| Company B | Shipping | 444 street |
+--------------+--------------+------------+
我有一张类似的桌子。
我需要的是帐单地址和送货地址不同的所有公司。
注意 - 每家公司只有一个帐单地址。但它可以有多个送货地址
这似乎是一个相当简单的查询,但我无法得到它。
我的尝试 - 我尝试从账单中“减去”所有送货地址,但没有输出。 不同也无济于事
查询:
select company_name
from tableA
where address_type='Billing'
and company_name not in (select to_char(company_name) from tableA where address_type='Shipping');
输出应该是公司B(因为它的帐单和送货地址不同)
编辑 1:尝试了 Indra 的查询,但它永远运行。没有回应
select A.* from company A inner join company B on A.company_Name = B.company_Name
and (A.address_type = 'Billing' and B.address_type = 'Shipping')
AND A.address <> B.address
【问题讨论】:
-
My attempt显示.. -
select company_name from tableA where address_type='Billing' and company_name not in (select to_char(company_name) from tableA where address_type='Shipping');
-
您使用的是什么数据库管理系统?甲骨文? MySQL? SQL Server?...