我有一个国家数据库和另一个名为区域的表.
Countries
[id, name, status (1 enabled 0 disabled) ]
Zones
[id, name, country_id]
我使用以下查询来匹配所有国家/地区的区域.
select
z.name as state,
z.id as state_id,
c.name as country_name,
c.id as country_id,
c.status as country_status
from countries c left join zones z on c.id = z.country_id
所以基本上简而言之,区域是状态,输出就是这样.
+-----------------------------------------------------+----------+--- -----------------------------------------+------------+----------------+
| state | state_id | country_name | country_id | country_status |
+-----------------------------------------------------+----------+--- -----------------------------------------+------------+----------------+
| NULL | NULL | Christmas Island | 45 | 1
| NULL | NULL | Puerto Rico | 172 | 1
| NULL | NULL Isle of Man | 254 | 1
| Álava | 2971 | Spain | 195 | 1
| Ávila | 2976 | Spain | 195 | 1
| Évora | 2656 | Portugal | 171 | 1
输出很大,粘贴在这里,所以只显示在结果的末尾
我想将国家/地区的状态更新为0,其中没有区域.知道我怎么能通过mySQL做到这一点?
解决方法:
你不能这样使用:
update Countries set status=0 where id not in (select distinct country_id from Zones )
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。