日期:2014-05-16  浏览次数:20672 次

求一条快速更新SQL语句
地区表
SQL code

CREATE TABLE `ecs_region` (
   `region_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
   `parent_id` smallint(5) unsigned NOT NULL DEFAULT '0',
   `region_name` varchar(120) NOT NULL DEFAULT '',
   `region_type` tinyint(1) NOT NULL DEFAULT '2',
   `agency_id` smallint(5) unsigned NOT NULL DEFAULT '0',
   PRIMARY KEY (`region_id`),
   KEY `parent_id` (`parent_id`),
   KEY `region_type` (`region_type`),
   KEY `agency_id` (`agency_id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8

region_id    parent_id    region_name    region_type    agency_id
1                0                中国         0                0
2                1                北京         1                0
3                1                安徽         1                0
4                1                福建         1                0
5                1                甘肃         1                0
//另外一个order表

CREATE TABLE `ecs_order_info` (
   
   `consignee` varchar(60) NOT NULL DEFAULT '',
   `country` smallint(5) unsigned NOT NULL DEFAULT '0',
   `province` smallint(5) unsigned NOT NULL DEFAULT '0',
   `city` smallint(5) unsigned NOT NULL DEFAULT '0',
   `district` smallint(5) unsigned NOT NULL DEFAULT '0',
 
 ) ENGINE=MyISAM
consignee          country         province        city           district
 收货人               0              1               2             XX地址 
用select语句查找ecs_order_info的时候,如何让查询的结果显示中文的收货人省市区?新建个列也行。能快速就好



------解决方案--------------------
select *,
(select region_name from ecs_region where region_id=a.country),
(select region_name from ecs_region where region_id=a.province),
(select region_name from ecs_region where region_id=a.city)
from ecs_order_info a