# 一道MySQL的笔试题

source link: http://caiknife.github.io/blog/2019/02/20/yi-dao-mysqlde-bi-shi-ti/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

# 一道MySQL的笔试题

Feb 20th, 2019

Posted by CaiKnife

Feb 20th, 2019mysql, 数据库

CREATE TABLE `rail` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`line` int(10) unsigned NOT NULL,
`stop` varchar(100) NOT NULL DEFAULT '',
`squence` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

INSERT INTO `rail`
(`id`, `line`, `stop`, `squence`)
VALUES
(1,1,'人民广场',10),
(2,2,'人民广场',11),
(3,8,'人民广场',9),
(4,2,'世纪大道',8),
(5,9,'世纪大道',12),
(6,11,'曹杨路',6),
(7,2,'静安寺',6),
(8,7,'静安寺',9);

1、查询经过站点最多的站点。

2、给出任意两条线路，查询这两条线路换乘的站点。

SELECT `stop`, count(`stop`) AS stop_count
FROM rail GROUP BY `stop` ORDER BY stop_count DESC LIMIT 1;

SELECT `stop` FROM tail WHERE `line`[email protected] AND `line`[email protected];

SELECT r1.stop FROM rail r1, rail r2
WHERE [email protected] AND [email protected] AND r1.stop=r2.stop;

Posted by CaiKnife

Feb 20th, 2019mysql, 数据库

## About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK