50,731
社区成员
发帖
与我相关
我的任务
分享
--查询余票
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';
好像我这样写的有问题,把站点当成数据统计了,其实应该统计站点到站点之间这一块,值提供一个参考哈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;