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的时候,如何让查询的结果显示中文的收货人省市区?新建个列也行。能快速就好
6 个解决方案
#1
要求结果是什么?递归查询?
#2
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
(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
#3
就是查询ecs_order_info的时候,能显示中文的省市区,效率不考虑!
#4
consignee country province city district
收货人 0 1 2 XX地址
0、1、2具体是什么?
#5
1
#6
数字代表的是地址表中的region_id
谢谢各位
#1
要求结果是什么?递归查询?
#2
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
(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
#3
就是查询ecs_order_info的时候,能显示中文的省市区,效率不考虑!
#4
consignee country province city district
收货人 0 1 2 XX地址
0、1、2具体是什么?
#5
1
#6
数字代表的是地址表中的region_id
谢谢各位