14-票价问题

create table person(
name string,
station string
)
row format delimited fields terminated by '\t'
lines terminated by '\n'
stored as textfile;
load data local inpath 'person.txt' into table person;

create table ticket(
station string,
money string
)
row format delimited fields terminated by '\t'
lines terminated by '\n'
stored as textfile;
load data local inpath 'ticket.txt' into table ticket;


条件过滤语句
case when xxx else xxxx end

问题1:按照站数算对应价格
select p.name,p.station,t.money
from person p,ticket t where p.station=t.station


问题2:10站以上打8折

case when condition then operation else operation end

select p.name,p.station,case when p.station>10 then t.money*0.8 else t.money end
from person p,ticket t where p.station=t.station


select p.name,case when t.station>10 then t.money*0.8 else t.money end
from person p,ticket t
where p.station = t.station

问题3:10-15站打9折、15站以上打8折

select p.name,p.station,case when p.station>10 then (case when p.station>15 then t.money*0.8 else t.money*0.9 end)  else t.money end
from person p,ticket t where p.station=t.station

select p.name,case when t.station>10 then (case when t.station>15 then t.money*0.8 else t.money*0.9 end) else t.money end
from person p,ticket t
where p.station = t.station

 

huang    26
lili    25
dongdong    13
wangxiao    5
1    5
2    5
3    5
4    5
5    5
6    5
7    5
8    5
9    5
10    10
11    10
12    10
13    10
14    10
15    10
16    10
17    10
18    30
19    30
20    30
21    30
22    30
23    30
24    30
25    30
26    30
27    30
28    30
29    30
30    30
31    30
32    30
33    30
34    30
35    30
36    30
37    30
38    30
39    30
40    30

 

 

转载于:https://www.cnblogs.com/JBLi/p/10842346.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
void search_flight() { // 查询航班信息 load_flights(); int choice; printf("1. 根据航班号查询航班信息\n"); printf("2. 根据起飞城市和目的城市查询航班信息\n"); printf("3. 根据航班号查询客户信息\n"); printf("请选择查询方式:"); scanf("%d", &choice); switch (choice) { case 1: // 根据航班号查询航班信息 char flight_no[10]; printf("请输入航班号:"); scanf("%s", flight_no); printf("\n查询结果:\n"); printf("航班号 起飞城市 目的城市 座位数 票价\n"); printf("-----------------------------------------------------------------\n"); int found = 0; for (int i = 0; i < num_flights; i++) { if (strcmp(flight_no, flights[i].flight_no) == 0) { display_flight(flights[i]); found = 1; break; } } if (!found) { printf("没有找到该航班!\n"); } break; case 2: // 根据起飞城市和目的城市查询航班信息 char departure[20], destination[20]; printf("请输入起飞城市:"); scanf("%s", departure); printf("请输入目的城市:"); scanf("%s", destination); printf("\n查询结果:\n"); printf("航班号 起飞城市 目的城市 座位数 票价\n"); printf("-----------------------------------------------------------------\n"); for (int i = 0; i < num_flights; i++) { if (strcmp(departure, flights[i].departure) == 0 && strcmp(destination, flights[i].destination) == 0) { display_flight(flights[i]); } } break; case 3: // 根据航班号查询客户信息 printf("请输入航班号:"); scanf("%s", flight_no); for (int i = 0; i < num_customers; i++) { if (strcmp(flight_no, customers[i].flight_no) == 0) { display_customer(customers[i]); } } break; default: printf("无效的选择,请重新输入!\n"); break; } }184 14 C:\Users\86195\Desktop\未命名1.cpp [Error] jump to case label [-fpermissive]报错修改
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值