求实现思路

JiaLingTianXia 2017-11-08 07:14:28
假设有一个车次1经过5个站,站点1,站点2,站点3,站点4,站点5(另外有一个车次2,经过站点3,站点4,站点6)
有3个座位,座位1,座位2,座位3
有乘客,买了站点1到站点3的座位1,站点4到站点5的座位1,
站点2到站点4的座位2,站点1到站点2的座位3,站点3到站点5的座位3,
自己确定数据库表的结构
问:怎么查到站点3到站点4的车次信息,它的余票,哪个座位有余票
需要实现思路
...全文
280 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
嘉凌天下 2017-11-10
  • 打赏
  • 举报
回复
题目是 有乘客,买了站点1到站点3的座位1,站点4到站点5的座位1, 意思是 站点1上 站点3 下 站点4上 站点5 下 站点3上到站点4下的没有卖出 车次一的站点3到站点4的车票没有卖,为什么isOrder 为1
小刀雨斑 2017-11-09
  • 打赏
  • 举报
回复
始终是两个相邻站点的票等于空位 跨站点 相当于求剩余票可组成改票的所有票数
自由自在_Yu 2017-11-09
  • 打赏
  • 举报
回复
--查询余票
select num,count(1) from train_order where isOrder = 0 and site = '站点3' or site = '站点4' group by num;
--查询空位
select num,site,seat_num from train_order where isOrder = 0 and site = '站点3' or site = '站点4';
好像我这样写的有问题,把站点当成数据统计了,其实应该统计站点到站点之间这一块,值提供一个参考哈
李德胜1995 2017-11-09
  • 打赏
  • 举报
回复
引用 2 楼 yuxiangaaaaa 的回复:
粗略的统计一下,一张表就可以了 code=sql]--订票信息表 drop table train_order; create table train_order( num varchar(6), --车次 site varchar(10),--站点 isOrder int,--是否预定:0-否,1-是 seat_num varchar(10),--座位号 order_people varchar(10),--预定人 primary key(num, site,seat_num) );[/code]
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点1', 1, '1', 'A');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点2', 1, '1', 'A');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点3', 1, '1', 'A');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点4', 1, '1', 'B');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点5', 1, '1', 'B');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点1', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点2', 1, '2', 'C');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点3', 1, '2', 'C');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点4', 1, '2', 'C');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点5', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点1', 1, '3', 'D');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点2', 1, '3', 'D');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点3', 1, '3', 'E');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点4', 1, '3', 'E');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点5', 1, '3', 'E');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点1', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点2', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点3', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点4', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点5', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点1', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点2', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点3', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点4', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点5', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点1', 0, '3', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点2', 0, '3', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点3', 0, '3', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点4', 0, '3', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点5', 0, '3', null);
--查询余票
select num,count(1) from train_order where isOrder = 0 group by num;
--查询空位
select num,site,seat_num from train_order where isOrder = 0;
自由自在_Yu 2017-11-09
  • 打赏
  • 举报
回复
粗略的统计一下,一张表就可以了 code=sql]--订票信息表 drop table train_order; create table train_order( num varchar(6), --车次 site varchar(10),--站点 isOrder int,--是否预定:0-否,1-是 seat_num varchar(10),--座位号 order_people varchar(10),--预定人 primary key(num, site,seat_num) );[/code]
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点1', 1, '1', 'A');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点2', 1, '1', 'A');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点3', 1, '1', 'A');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点4', 1, '1', 'B');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点5', 1, '1', 'B');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点1', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点2', 1, '2', 'C');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点3', 1, '2', 'C');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点4', 1, '2', 'C');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点5', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点1', 1, '3', 'D');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点2', 1, '3', 'D');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点3', 1, '3', 'E');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点4', 1, '3', 'E');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次1', '站点5', 1, '3', 'E');
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点1', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点2', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点3', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点4', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点5', 0, '1', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点1', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点2', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点3', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点4', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点5', 0, '2', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点1', 0, '3', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点2', 0, '3', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点3', 0, '3', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点4', 0, '3', null);
INSERT INTO TRAIN_ORDER (NUM, SITE, ISORDER, SEAT_NUM, ORDER_PEOPLE) VALUES ('车次2', '站点5', 0, '3', null);
--查询余票
select num,count(1) from train_order where isOrder = 0 group by num;
--查询空位
select num,site,seat_num from train_order where isOrder = 0;
自由自在_Yu 2017-11-09
  • 打赏
  • 举报
回复
有乘客,买了站点1到站点3的座位1,站点4到站点5的座位1, 站点2到站点4的座位2,站点1到站点2的座位3,站点3到站点5的座位3,这些事车次1的还是车次2的?

50,731

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧