create table provincial
(
provincialID int,
provincialName varchar(50),
primary key (provincialID)
)engine=INNODB default charset=gbk
insert into provincial values(1,'北京市')
insert into provincial values(2,'天津市')
insert into provincial values(3,'上海市')
insert into provincial values(4,'重庆市')
insert into provincial values(5,'河北省')
insert into provincial values(6,'山西省')
insert into provincial values(7,'台湾省')
insert into provincial values(8,'辽宁省')
insert into provincial values(9,'吉林省')
insert into provincial values(10,'黑龙江省')
insert into provincial values(11,'江苏省')
insert into provincial values(12,'浙江省')
insert into provincial values(13,'安徽省')
insert into provincial values(14,'福建省')
insert into provincial values(15,'江西省')
insert into provincial values(16,'山东省')
insert into provincial values(17,'河南省')
insert into provincial values(18,'湖北省')
insert into provincial values(19,'湖南省')
insert into provincial values(20,'广东省')
insert into provincial values(21,'甘肃省')
insert into provincial values(22,'四川省')
insert into provincial values(23,'贵州省')
insert into provincial values(24,'海南省')
insert into provincial values(25,'云南省')
insert into provincial values(26,'青海省')
insert into provincial values(27,'陕西省')
insert into provincial values(28,'广西壮族自治区')
insert into provincial values(29,'西藏自治区')
insert into provincial values(30,'宁夏回族自治区')
insert into provincial values(31,'新疆维吾尔自治区')
insert into provincial values(32,'内蒙古自治区')
insert into provincial values(33,'澳门特别行政区')
insert into provincial values(34,'香港特别行政区')
select provincialID,provincialName from provincial
--城市 city
create table city
(
cityID int not null,
cityName varchar(50) not null,
provincialID int not null,
primary key (cityID)
)engine=INNODB default charset=gbkalter table city add constraint FK_pro_city_provincialID foreign key (provincialID)
references provincial (provincialID)
----------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
--插入各个省的城市数据
--4个直辖市
insert into city values(1,'北京市',1)
insert into city values(2,'天津市',2)
insert into city values(3,'上海市',3)
insert into city values(4,'重庆市',4)
--select * from city where provincialID=4
----------------------------------------------------------------
--5河北省 11个地级市
insert into city values(5,'石家庄市',5)
insert into city values(6,'唐山市',5)
insert into city values(7,'秦皇岛市',5)
insert into city values(8,'邯郸市',5)
insert into city values(9,'邢台市',5)
insert into city values(10,'保定市',5)
insert into city values(11,'张家口市',5)
insert into city values(12,'承德市',5)
insert into city values(13,'沧州市',5)
insert into city values(14,'廊坊市',5)
insert into city values(15,'衡水市',5)
--select * from city where provincialID=5 order by cityID
----------------------------------------------------------------
--6山西省 11个城市
insert into city values(16,'太原市',6)
insert into city values(17,'大同市',6)
insert into city values(18,'阳泉市',6)
insert into city values(19,'长治市',6)
insert into city values(20,'晋城市',6)
insert into city values(21,'朔州市',6)
insert into city values(22,'晋中市',6)
insert into city values(23,'运城市',6)
insert into city values(24,'忻州市',6)
insert into city values(25,'临汾市',6)
insert into city values(26,'吕梁市',6)
--select * from city where provincialID=6 order by cityID
----------------------------------------------------------------
--7台湾省(台湾本岛和澎湖共设7市、16县,其中台北市和高雄市为“院辖市”,直属“行政院”,其余属台湾省;市下设区,县下设市(县辖市)、镇、乡,合称区市镇乡。)
insert into city values(27,'台北市',7)
insert into city values(28,'高雄市',7)
insert into city values(29,'基隆市',7)
insert into city values(30,'台中市',7)
insert into city values(31,'台南市',7)
insert into city values(32,'新竹市',7)
insert into city values(33,'嘉义市',7)
insert into city values(34,'台北县',7)
insert into city values(35,'宜兰县',7)
insert into city values(36,'桃园县',7)
insert into city values(37,'新竹县',7)
insert into city values(38,'苗栗县',7)
insert into city values(39,'台中县',7)
insert into city values(40,'彰化县',7)
insert into city values(41,'南投县',7)
insert into city values(42,'云林县',7)
insert into city values(43,'嘉义县',7)
insert into city values(44,'台南县',7)
insert into city values(45,'高雄县',7)
insert into city values(46,'屏东县',7)
insert into city values(47,'澎湖县',7)
insert into city values(48,'台东县',7)
insert into city values(49,'花莲县',7)
--select * from city where provincialID=7 order by cityID
----------------------------------------------------------------
--8辽宁省 14个地级市
insert into city values(50,'沈阳市',8)
insert into city values(51,'大连市',8)
insert into city values(52,'鞍山市',8)
insert into city values(53,'抚顺市',8)
insert into city values(54,'本溪市',8)
insert into city values(55,'丹东市',8)
insert into city values(56,'锦州市',8)
insert into city values(57,'营口市',8)
insert into city values(58,'阜新市',8)
insert into city values(59,'辽阳市',8)
insert into city values(60,'盘锦市',8)
insert into city values(61,'铁岭市',8)
insert into city values(62,'朝阳市',8)
insert into city values(63,'葫芦岛市',8)
--select * from city where provincialID=8 order by cityID
----------------------------------------------------------------
--9吉林省(2006年,辖:8个地级市、1个自治州;20个市辖区、20个县级市、17个县、3个自治县。)
insert into city values(64,'长春市',9)
insert into city values(65,'吉林市',9)
insert into city values(66,'四平市',9)
insert into city values(67,'辽源市',9)
insert into city values(68,'通化市',9)
insert into city values(69,'白山市',9)
insert into city values(70,'松原市',9)
insert into city values(71,'白城市',9)
insert into city values(72,'延边朝鲜族自治州',9)
--select * from city where provincialID=9 order by cityID
----------------------------------------------------------------
--10黑龙江省(2006年,辖:12地级市、1地区;64市辖区、18县级市、45县、1自治县)
insert into city values(73,'哈尔滨市',10)
insert into city values(74,'齐齐哈尔市',10)
insert into city values(75,'鹤 岗 市',10)
insert into city values(76,'双鸭山市',10)
insert into city values(77,'鸡 西 市',10)
insert into city values(78,'大 庆 市',10)
insert into city values(79,'伊 春 市',10)
insert into city values(80,'牡丹江市',10)
insert into city values(81,'佳木斯市',10)
insert into city values(82,'七台河市',10)
insert into city values(83,'黑 河 市',10)
insert into city values(84,'绥 化 市',10)
insert into city values(85,'大兴安岭地区',10)
--select * from city where provincialID=10 order by cityID
----------------------------------------------------------------
--11江苏省(2005年辖:13个地级市;54个市辖区、27个县级市、25个县)
insert into city values(86,'南京市',11)
insert into city values(87,'无锡市',11)
insert into city values(88,'徐州市',11)
insert into city values(89,'常州市',11)
insert into city values(90,'苏州市',11)
insert into city values(91,'南通市',11)
insert into city values(92,'连云港市',11)
insert into city values(93,'淮安市',11)
insert into city values(94,'盐城市',11)
insert into city values(95,'扬州市',11)
insert into city values(96,'镇江市',11)
insert into city values(97,'泰州市',11)
insert into city values(98,'宿迁市',11)
--select * from city where provincialID=11 order by cityID
----------------------------------------------------------------
--12浙江省(2006年,辖:11个地级市;32个市辖区、22个县级市、35个县、1个自治县。)
insert into city values(99,'杭州市',12)
insert into city values(100,'宁波市',12)
insert into city values(101,'温州市',12)
insert into city values(102,'嘉兴市',12)
insert into city values(103,'湖州市',12)
insert into city values(104,'绍兴市',12)
insert into city values(105,'金华市',12)
insert into city values(106,'衢州市',12)
insert into city values(107,'舟山市',12)
insert into city values(108,'台州市',12)
insert into city values(109,'丽水市',12)
--select * from city where provincialID=12 order by cityID
---------------------------------------------------------------- 没有写完, 写不下了,你加我! 775790318
(1)要求查找”中国河北省“的所有县名。该如何查找,写出SQL语句SELECT
县郡表.县郡名
FROM
国家表 JOIN 省市表 ON ( 国家表.国家编号 = 省市表.国家编号 )
JOIN 县郡表 ON ( 县郡表.省市编号 = 省市表.省市编号 )
WHERE
国家表.国名 = '中国' AND 省市表.省市名 = '河北'
(2)在功能不变的前提下,将上述三表合并成一个表,该如何设计?在你的设计中,实现上述查找的SQL语句该如何写
CREATE TABLE 国省县 (
国名:vARCHAR(50),
省市名:varchar(50),
县郡名:VarChar(50)
)
SELECT
县郡名
FROM
国省县
WHERE
国名 = '中国' AND 省市名 = '河北'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)