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

问题描述


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

推荐答案

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


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>



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

09-21 14:40