通过联接提取许多列 [英] Extract a many columns through Join

查看:98
本文介绍了通过联接提取许多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


1.实体
EntityId名称
1拉杰尼
2 neha

2.许可证

LicenseId EntityId LicenseType
1. 1我
2. 2 F

3. EntityAddress

AddressId实体AddressType城市州
1 1 MLG Ggn哈里亚纳邦
2 1 BUS HHN上
3 2 MLG XY kl
4 2 BUS GH HJ

现在,我想基于EntityId n LicenseType提取City n州
如果LicenseType为"I",则THEN AddressType为"MLG",城市为n个州
如果许可证类型为"F",则地址类型为"BUS",城市名称为state

Table
1. Entity
EntityId Name
1 Rajni
2 neha

2. License

LicenseId EntityId LicenseType
1. 1 I
2. 2 F

3. EntityAddress

AddressId Entity AddressType City State
1 1 MLG Ggn Haryana
2 1 BUS HHN Up
3 2 MLG XY kl
4 2 BUS GH HJ

Now, I want to extract City n state on basis of EntityId n LicenseType
if LicenseType "I",THEN AddressType "MLG" city n state come
if LicenseType "F",THEN AddressType "BUS" city n state come

推荐答案

,请尝试执行此查询.
据我了解的问题,这就是您要查询的内容.
如果误解了,抱歉.如果没有,请给我更多的说明.

Please try this Query.
As far as I understood ur question, this is the query what u r asking.
sorry if misunderstood.if not please give me some more clarity.

SELECT EA.City,EA.State,EA.AddressType FROM EntityAddress EA INNER JOIN License L ON EA.EntityId=L.EntityId WHERE L.LicenseType="GivenLicenseType"


尝试一下.

Try this.

select L.LicenseType, EA.Address,EA.city,EA.sate from Entity E 
left outer join License L on E.EntityId = L.EntityId
left outer join EntityAddress EA on EA.Entity = L.EntityId
where E.EntityId = <entityid> and L.LicenseType = '<licensetype>'</licensetype></entityid>


选择L.LicenseType,EA.Address,EA.city,EA.sate
来自实体E
左外部加入许可证L
在E.EntityId = L.EntityId
左外连接EntityAddress EA
在EA.Entity = L.EntityId
在哪里(L.licenseType =''I''AND EA.AddressType =''MLG'')
或(L.licenseType =''F''AND EA.AddressType =''BUS'')
select L.LicenseType, EA.Address,EA.city,EA.sate
from Entity E
left outer join License L
on E.EntityId = L.EntityId
left outer join EntityAddress EA
on EA.Entity = L.EntityId
WHERE (L.licenseType=''I'' AND EA.AddressType=''MLG'')
OR (L.licenseType=''F'' AND EA.AddressType=''BUS'')


这篇关于通过联接提取许多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆