gpt4 book ai didi

sql - 多级级联内连接选择查询

转载 作者:搜寻专家 更新时间:2023-10-30 19:45:21 25 4
gpt4 key购买 nike

我有以下表格结构 enter image description here

我想从 short_name(国家名称)、名称(状态表)或 region_name 的任何可用数据中选择 post_id。执行以下查询结果为 region_name 但不是 short_name(country name), name (state table)。

select *
from t_post_city
inner join t_region on t_region.region_id = t_post_city.city_id
inner join t_country on t_region.country_id = t_country.country_id
inner join t_states on t_region.province_id = t_states.state_id
where t_country.short_name like %india%
or t_states.name like %rajasthan%
or t_region.region_name like %sitapura%

请告诉我,我错在哪里!

最佳答案

select *
from t_post_city
LEFT OUTER join t_region on t_region.region_id = t_post_city.city_id
LEFT OUTER join t_country on t_region.country_id = t_country.country_id
LEFT OUTER join t_states on t_region.province_id = t_states.state_id
where t_country.short_name like '%india%'
or t_states.name like '%rajasthan%'
or t_region.region_name like '%sitapura%'

关于sql - 多级级联内连接选择查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40043776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com