drop table if exists user;
create table user(
  user_id int(11) primary key auto_increment,
  username varchar(255),
  password varchar(255),
  bank_card varchar(55) comment '卡号',
  balance decimal(10,2) comment '余额'
);
insert into user (username,password,bank_card,balance) values ('jack','jack','62251658492230',10000);
insert into user (username,password,bank_card,balance) values ('lucy','lucy','62251658496379',9000);
insert into user (username,password,bank_card,balance) values ('jury','jury','62251698848230',6000);

select user_id,username, password, bank_card,balance from user where username = 'jack';


select
    u.user_id,
    u.username,
    u.password,
    b.bank_name,
    ub.bank_card,
    ub.balance
from
    user u
        left join t_user_bank ub on u.user_id = ub.user_id
        left join t_bank b on ub.bank_id = b.bank_id
where ub.user_id = 1;


drop table if exists t_bank;
create table t_bank(
  bank_id int(11) primary key auto_increment,
  bank_name varchar(55) comment '名称'
);
insert into t_bank (bank_name) values ('中国工商银行');
insert into t_bank (bank_name) values ('中国农业银行');
select bank_id, bank_name from t_bank;

drop table if exists t_user_bank;
create table t_user_bank(
  id int(11) primary key auto_increment,
  user_id int(11) comment '用户',
  bank_id int(11) comment '银行',
  bank_card varchar(55) comment '卡号',
  balance decimal(10,2) comment '余额'
);
insert into t_user_bank (user_id,bank_id,bank_card,balance) values (1,1,'62251658492230',10000);
insert into t_user_bank (user_id,bank_id,bank_card,balance) values (1,2,'62251698732230',6000);

insert into t_user_bank (user_id,bank_id,bank_card,balance) values (2,1,'62251658496379',15000);

insert into t_user_bank (user_id,bank_id,bank_card,balance) values (3,2,'62251698848230',9000);

select id,user_id,bank_id,bank_card,balance from t_user_bank;





-- 景区表
drop table if exists t_scenic;
create table t_scenic(
  scenic_id int(11) comment '景区主键' primary key auto_increment,
  scenic_name varchar(55) comment '景区名称',
  introduction varchar(255) comment '景区介绍',
  fares decimal(10,2) comment '票价',
  remaining_votes int(11) comment '剩余票数'
);
insert into t_scenic (scenic_name, introduction, fares, remaining_votes) values ('海湾国家森林公园','4A级景区',80,999);
insert into t_scenic (scenic_name, introduction, fares, remaining_votes) values ('东方明珠','上海地标建筑之一',258,30);
insert into t_scenic (scenic_name, introduction, fares, remaining_votes) values ('滴水湖','可以体验碧水蓝天的感觉',0,99);
insert into t_scenic (scenic_name, introduction, fares, remaining_votes) values ('欢乐谷','拥有中国最高的过山车',360,255);
select scenic_id, scenic_name, introduction, fares, remaining_votes from t_scenic
where
    fares >= 200 and fares <= 300 or
    scenic_name like '%东方%';

-- 订单表
drop table if exists t_order;
create table t_order(
  order_id int(11) comment '订单主键' primary key auto_increment,
  user_id int(11) comment '用户',
  scenic_name varchar(55) comment '景区名称',
  introduction varchar(255) comment '景区介绍',
  fares decimal(10,2) comment '票价',
  votes int(11) comment '票数',
  total_fares decimal(10,2) comment '总价',
  pay_card varchar(55) comment '支付银行卡号',
  pay_time datetime comment '支付时间'
);
insert into t_order (user_id,scenic_name,introduction,fares,votes,total_fares,pay_card,pay_time) values (1,'海湾国家森林公园','4A级景区',80,3,240,'62251658492230','2023-10-7 8:00');
insert into t_order (user_id,scenic_name,introduction,fares,votes,total_fares,pay_card,pay_time) values (1,'东方明珠','上海地标建筑之一',258,2,516,'62251658492230','2023-10-7 9:00');
insert into t_order (user_id,scenic_name,introduction,fares,votes,total_fares,pay_card,pay_time) values (1,'滴水湖','可以体验碧水蓝天的感觉',0,3,0,'62251658492230','2023-10-7 10:00');
insert into t_order (user_id,scenic_name,introduction,fares,votes,total_fares,pay_card,pay_time) values (1,'欢乐谷','拥有中国最高的过山车',360,3,1080,'62251658492230','2023-10-7 15:00');

insert into t_order (user_id,scenic_name,introduction,fares,votes,total_fares,pay_card,pay_time) values (2,'东方明珠','上海地标建筑之一',258,1,258,'62251658496379','2023-10-7 8:05');

insert into t_order (user_id,scenic_name,introduction,fares,votes,total_fares,pay_card,pay_time) values (3,'欢乐谷','拥有中国最高的过山车',360,2,720,'62251698848230','2023-10-7 10:00');
select order_id,user_id,scenic_name,introduction,fares,votes,total_fares,pay_card,pay_time from t_order where user_id = 1 and scenic_name like '%东方%';
