当前位置:Gxlcms > 数据库问题 > 火车票订票系统的数据库设计与实现(某某乐后端实习面试题)

火车票订票系统的数据库设计与实现(某某乐后端实习面试题)

时间:2021-07-01 10:21:17 帮助过:43人阅读

,‘20190502120000‘,‘2‘,‘522131199901016667‘);   表3 车票表 create table tickets( ticket_id varchar(18) primary key, train_number varchar(10) not null, start_station char(11) not null, arrive_station varchar(16) not null, seat_type varchar(18) not null, price varchar(18), go_time timestamp, arrive_time timestamp, type varchar(18), order_number varchar(18) ); insert into tickets values(‘ticket201904200001‘,‘Z49‘,‘上海‘,‘杭州‘,‘硬座‘,‘20.00‘,‘2019-04-20 21:01:00‘,‘2019-04-20 22:00:00‘,‘成人票‘,‘201904200001‘); insert into tickets values(‘ticket201904200002‘,‘Z50‘,‘嘉兴‘,‘杭州‘,‘硬座‘,‘10.00‘,‘2019-04-02 21:00:00‘,‘2019-04-02 22:00:00‘,‘成人票‘,‘201904020001‘); insert into tickets values(‘ticket201904200003‘,‘Z50‘,‘上海‘,‘南京‘,‘硬座‘,‘10.00‘,‘2019-04-02 21:00:00‘,‘2019-04-02 22:00:00‘,‘成人票‘,‘201904020004‘); insert into tickets values(‘ticket201904200004‘,‘Z50‘,‘上海‘,‘杭州‘,‘硬卧‘,‘10.00‘,‘2019-04-02 21:00:00‘,‘2019-04-02 22:00:00‘,‘成人票‘,‘201904020005‘); insert into tickets values(‘ticket201904200005‘,‘G11‘,‘上海‘,‘武汉‘,‘硬座‘,‘10.00‘,‘2019-04-02 21:00:00‘,‘2019-04-02 22:00:00‘,‘成人票‘,‘201904020001‘);   三、具体查询需求分析: 日期处理:arrive_time只需要日期+时分。 建表的时候有五种: https://www.cnblogs.com/Jie-Jack/p/3793304.html 查询的时候: 需要格式化,DATE_FORMAT(tickets.arrive_time,‘%Y%m%d %H:%i:%s‘ select date_format(order_time,‘%Y-%m-%d %H:%m‘) order_time from orders; 技术图片 技术图片

 

  主要是车票表的查询: (1)需求:查询所有从上海出发到杭州的火车的车次,起点,终点站,席位,价格,出发时间 select train_number as 车次, start_station as 起点, arrive_station as 终点, seat_type as 席位, price as 价格, date_format(go_time,‘%Y-%m-%d %H:%m‘) 出发时间 from tickets where start_station = ‘上海‘ and arrive_station = ‘杭州‘; 技术图片 技术图片 技术图片

技术图片

 

type字段显示为All,没有用到索引。   (2)优化:为了加快查找速度,给始发站和终点站添加复合索引 alter table tickets add index idx_start_arrive(start_station,arrive_station); 技术图片 技术图片技术图片 type字段为ref,性能优化较好。   表结构参考了: http://www.mayiwenku.com/p-5808164.html

火车票订票系统的数据库设计与实现(某某乐后端实习面试题)

标签:jdb   dba   客户   round   owa   www.   okr   ted   gas   

人气教程排行