数据库代码

main
zhangas2 5 months ago
parent eefb1d60a2
commit fce85cc0bb

@ -0,0 +1,181 @@
create database parkinglot;
USE parkinglot;
create table parkingspotinformation
(
parking_spot_id int not null
primary key,
spot_type varchar(100) null,
occupancy_status int null,
location varchar(255) null,
fee_standard decimal(10, 2) null
)
engine = InnoDB;
create table userinformation
(
user_id int not null
primary key,
name varchar(255) not null,
telephone varchar(11) null,
user_type varchar(100) null,
parking_spot_id int null,
address varchar(255) null,
gender varchar(10) null,
constraint parking_spot_id
unique (parking_spot_id),
constraint userinformation_ibfk_1
foreign key (parking_spot_id) references parkingspotinformation (parking_spot_id)
)
engine = InnoDB;
create table accountinformation
(
account_id int not null
primary key,
user_id int null,
account_type varchar(100) null,
account_status varchar(50) null,
name varchar(255) null,
password varchar(255) null,
constraint user_id
unique (user_id),
constraint accountinformation_ibfk_1
foreign key (user_id) references userinformation (user_id)
)
engine = InnoDB;
create table icinformation
(
user_id int null,
card_number varchar(20) not null
primary key,
password varchar(255) null,
balance decimal(10, 2) null,
constraint user_id
unique (user_id),
constraint icinformation_ibfk_1
foreign key (user_id) references userinformation (user_id)
)
engine = InnoDB;
DELIMITER //
create definer = root@localhost trigger update_fee_standard
after update
on userinformation
for each row
BEGIN
IF NEW.user_type = 'vip' AND OLD.user_type = 'user' THEN
UPDATE parkingspotinformation
SET fee_standard = 0.75
WHERE parking_spot_id = NEW.parking_spot_id;
END IF;
END;
//
DELIMITER ;
create table vehicleinformation
(
car_license varchar(20) not null
primary key,
user_id int null,
brand varchar(100) null,
model varchar(100) null,
constraint user_id
unique (user_id),
constraint vehicleinformation_ibfk_1
foreign key (user_id) references userinformation (user_id)
)
engine = InnoDB;
create table parkingrecord
(
record_id int auto_increment
primary key,
parking_spot_id int null,
start_time datetime null,
parking_fee decimal(10, 2) null,
end_time datetime null,
car_license varchar(20) null,
constraint parkingrecord_ibfk_1
foreign key (parking_spot_id) references parkingspotinformation (parking_spot_id),
constraint parkingrecord_ibfk_2
foreign key (car_license) references vehicleinformation (car_license)
)
engine = InnoDB;
create index car_license
on parkingrecord (car_license);
create index parking_spot_id
on parkingrecord (parking_spot_id);
DELIMITER //
create definer = root@localhost trigger calculate_and_deduct_parking_fee
before update
on parkingrecord
for each row
BEGIN
DECLARE spot_fee DECIMAL(10, 2);
DECLARE hours_parked INT;
IF NEW.end_time IS NOT NULL AND OLD.end_time IS NULL THEN
-- 获取停车费率
SELECT fee_standard INTO spot_fee FROM parkingspotinformation WHERE parking_spot_id = NEW.parking_spot_id;
-- 计算停车时间(小时)
SET hours_parked = GREATEST(CEIL(TIMESTAMPDIFF(MINUTE, NEW.start_time, NEW.end_time) / 60), 1);
-- 更新停车费用
SET NEW.parking_fee = hours_parked * spot_fee;
-- 扣除停车费用
UPDATE icinformation
SET balance = balance - NEW.parking_fee
WHERE user_id = (SELECT user_id FROM userinformation WHERE parking_spot_id = NEW.parking_spot_id);
END IF;
END;
//
DELIMITER ;
DELIMITER //
create definer = root@localhost trigger calculate_parking_fee
before update
on parkingrecord
for each row
BEGIN
IF NEW.end_time IS NOT NULL AND OLD.end_time IS NULL THEN
SET @hours_parked = GREATEST(CEIL(TIMESTAMPDIFF(MINUTE, NEW.start_time, NEW.end_time) / 60), 1);
SET @spot_fee = (SELECT fee_standard FROM parkingspotinformation WHERE parking_spot_id = NEW.parking_spot_id);
SET NEW.parking_fee = @hours_parked * @spot_fee;
END IF;
END;
//
DELIMITER ;
create definer = root@localhost view parking_record_view as
select `pr`.`record_id` AS `record_id`,
`pr`.`parking_spot_id` AS `parking_spot_id`,
`pr`.`start_time` AS `start_time`,
`pr`.`parking_fee` AS `parking_fee`,
`pr`.`end_time` AS `end_time`,
`pr`.`car_license` AS `car_license`,
`psi`.`location` AS `location`
from (`parkinglot`.`parkingrecord` `pr` left join `parkinglot`.`parkingspotinformation` `psi`
on ((`pr`.`parking_spot_id` = `psi`.`parking_spot_id`)));
create definer = root@localhost view userparkingtotalfees as
select `u`.`name` AS `user_name`, sum(`pr`.`parking_fee`) AS `total_parking_fees`
from (`parkinglot`.`userinformation` `u` left join `parkinglot`.`parkingrecord` `pr`
on ((`u`.`parking_spot_id` = `pr`.`parking_spot_id`)))
group by `u`.`name`;
create definer = root@localhost view vehicleuserview as
select `vi`.`car_license` AS `car_license`,
`vi`.`brand` AS `brand`,
`vi`.`model` AS `model`,
`ui`.`name` AS `name`,
`ui`.`telephone` AS `telephone`,
`ui`.`address` AS `address`
from (`parkinglot`.`vehicleinformation` `vi` join `parkinglot`.`userinformation` `ui`
on ((`vi`.`user_id` = `ui`.`user_id`)));

@ -0,0 +1,35 @@
-- 删除长时间未支付停车费的用户车辆信息和相关记录
DELETE FROM VehicleInformation
WHERE user_id IN (
SELECT ui.user_id
FROM UserInformation ui
JOIN ParkingRecord pr ON ui.user_id = pr.user_id
WHERE pr.parking_fee > 0 AND pr.end_time < NOW() - INTERVAL 30 DAY
);
-- 删除用户的 ICCardInformation 信息
DELETE FROM ICCardInformation
WHERE user_id IN (
SELECT ui.user_id
FROM UserInformation ui
JOIN ParkingRecord pr ON ui.user_id = pr.user_id
WHERE pr.parking_fee > 0 AND pr.end_time < NOW() - INTERVAL 30 DAY
);
-- 删除用户车辆信息
DELETE FROM UserInformation
WHERE user_id IN (
SELECT ui.user_id
FROM UserInformation ui
JOIN ParkingRecord pr ON ui.user_id = pr.user_id
WHERE pr.parking_fee > 0 AND pr.end_time < NOW() - INTERVAL 30 DAY
);
-- 释放过去一年内未使用过的停车位
DELETE FROM ParkingSpotInformation
WHERE parking_spot_id NOT IN (
SELECT DISTINCT parking_spot_id
FROM ParkingRecord
WHERE end_time > NOW() - INTERVAL 1 YEAR
);

@ -0,0 +1,181 @@
-- 用户表初始化脚本:
INSERT INTO userinformation (user_id, name, telephone, user_type, parking_spot_id, address, gender)
VALUES
(32, '张作为', '15990942057', 'vip', 32, '14号楼-1单元-209', ''),
(1, '张三', '15900010001', 'user', 1, '1号楼-1单元-101', ''),
(2, '李四', '15900020002', 'user', 2, '2号楼-2单元-102', ''),
(3, '王五', '15900030003', 'user', 3, '3号楼-3单元-103', ''),
(4, '赵六', '15900040004', 'user', 4, '4号楼-4单元-104', ''),
(5, '钱七', '15900050005', 'user', 5, '5号楼-5单元-105', ''),
(6, '孙八', '15900060006', 'user', 6, '6号楼-6单元-106', ''),
(7, '周九', '15900070007', 'user', 7, '7号楼-7单元-107', ''),
(8, '吴十', '15900080008', 'user', 8, '8号楼-8单元-108', ''),
(9, '郑十一', '15900090009', 'user', 9, '9号楼-9单元-109', ''),
(10, '王十二', '15900100010', 'user', 10, '10号楼-10单元-110', ''),
(11, '赵十三', '15900110011', 'user', 11, '11号楼-11单元-111', ''),
(12, '钱十四', '15900120012', 'user', 12, '12号楼-12单元-112', ''),
(13, '孙十五', '15900130013', 'user', 13, '13号楼-13单元-113', ''),
(14, '李十六', '15900140014', 'user', 14, '14号楼-14单元-114', ''),
(15, '吴十七', '15900150015', 'user', 15, '15号楼-15单元-115', ''),
(16, '周十八', '15900160016', 'user', 16, '16号楼-16单元-116', ''),
(17, '郑十九', '15900170017', 'user', 17, '17号楼-17单元-117', ''),
(18, '王二十', '15900180018', 'user', 18, '18号楼-18单元-118', ''),
(19, '赵二十一', '15900190019', 'user', 19, '19号楼-19单元-119', ''),
(20, '钱二十二', '15900200020', 'user', 20, '20号楼-20单元-120', ''),
(21, '孙二十三', '15900210021', 'user', 21, '21号楼-21单元-121', ''),
(22, '李二十四', '15900220022', 'user', 22, '22号楼-22单元-122', ''),
(23, '吴二十五', '15900230023', 'user', 23, '23号楼-23单元-123', ''),
(24, '周二十六', '15900240024', 'user', 24, '24号楼-24单元-124', ''),
(25, '郑二十七', '15900250025', 'user', 25, '25号楼-25单元-125', ''),
(26, '王二十八', '15900260026', 'user', 26, '26号楼-26单元-126', ''),
(27, '赵二十九', '15900270027', 'user', 27, '27号楼-27单元-127', ''),
(28, '钱三十', '15900280028', 'user', 28, '28号楼-28单元-128', ''),
(29, '孙三十一', '15900290029', 'user', 29, '29号楼-29单元-129', ''),
(30, '李三十二', '15900300030', 'user', 30, '30号楼-30单元-130', ''),
(31, '吴三十三', '15900310031', 'user', 31, '31号楼-31单元-131', '');
-- 车辆表初始化脚本:
INSERT INTO vehicleinformation (car_license, user_id, brand, model)
VALUES
('苏M6L756', 1, '奥迪', 'A4'),
('苏DY0001', 2, '丰田', '卡罗拉'),
('云E00000', 3, '本田', '雅阁'),
('津NK0133', 4, '大众', '帕萨特'),
('京A80930', 5, '宝马', '3系'),
('京A63708', 6, '奔驰', 'C级'),
('辽JB2368', 7, '特斯拉', 'Model 3'),
('京A55069', 8, '丰田', '凯美瑞'),
('鲁P54250', 9, '雪佛兰', '科鲁兹'),
('京PT3G98', 10, '别克', '君越'),
('沪KB3517', 11, '现代', '索纳塔'),
('渝DB1618', 12, '日产', '轩逸'),
('京F16888', 13, '雪铁龙', 'C4世嘉'),
('黑AF6655', 14, 'Jeep', '自由光'),
('川AE5V08', 15, '本田', 'CR-V'),
('晋KWV587', 16, '福特', '福克斯'),
('闽A88888', 17, '奔驰', 'E级'),
('黑A17K98', 18, '丰田', '兰德酷路泽'),
('京H99999', 19, '宝马', '5系'),
('沪KR9888', 20, '奥迪', 'A6'),
('粤B6Y889', 21, '大众', '迈腾'),
('辽BSZ889', 22, '现代', '胜达'),
('苏E05EV8', 23, '丰田', '普拉多'),
('皖B12GA1', 24, '雪佛兰', '迈锐宝'),
('京Q58A77', 25, '特斯拉', 'Model S'),
('豫CN6666', 26, '本田', '思域'),
('闽B8888P', 27, '别克', '英朗'),
('辽JF4093', 28, '雪佛兰', '赛欧'),
('沪B69999', 29, '丰田', '普锐斯'),
('浙A66666', 30, '大众', '高尔夫'),
('冀A636P8', 31, '别克', 'GL8');
-- 停车记录表初始化脚本:
INSERT INTO parkingrecord (parking_spot_id, start_time, parking_fee, end_time, car_license)
VALUES
(1, '2024-12-03 09:15:27', 1.50, '2024-12-03 09:17:14', '苏M6L756'),
(2, '2024-12-04 10:30:42', 1.50, '2024-12-04 10:32:29', '沪KB3517'),
(3, '2024-12-05 11:45:56', 1.50, '2024-12-05 11:47:43', '辽JB2368'),
(4, '2024-12-06 13:00:11', 1.50, '2024-12-06 13:01:58', '粤B6Y889'),
(5, '2024-12-07 14:15:25', 1.50, '2024-12-07 14:17:12', '京A55069'),
(6, '2024-12-08 15:30:40', 1.50, '2024-12-08 15:32:27', '苏E05EV8'),
(7, '2024-12-09 16:45:54', 1.50, '2024-12-09 16:47:41', '辽BSZ889'),
(8, '2024-12-10 18:00:08', 1.50, '2024-12-10 18:01:55', '冀A636P8'),
(9, '2024-12-11 19:15:23', 1.50, '2024-12-11 19:17:10', '浙A66666'),
(10, '2024-12-12 20:30:37', 1.50, '2024-12-12 20:32:24', '鲁P54250'),
(11, '2024-12-13 21:45:52', 1.50, '2024-12-13 21:47:39', '苏E05EV8'),
(12, '2024-12-14 23:00:06', 1.50, '2024-12-14 23:01:53', '京A63708'),
(13, '2024-12-15 00:15:21', 1.50, '2024-12-15 00:17:08', '沪KR9888'),
(14, '2024-12-16 01:30:35', 1.50, '2024-12-16 01:32:22', '川AE5V08'),
(15, '2024-12-17 02:45:50', 1.50, '2024-12-17 02:47:37', '冀A636P8'),
(16, '2024-12-18 04:00:04', 1.50, '2024-12-18 04:01:51', '豫CN6666'),
(17, '2024-12-19 05:15:18', 1.50, '2024-12-19 05:17:05', '黑A17K98'),
(18, '2024-12-20 06:30:33', 1.50, '2024-12-20 06:32:20', '苏E05EV8'),
(19, '2024-12-21 07:45:47', 1.50, '2024-12-21 07:47:34', '苏DY0001'),
(20, '2024-12-22 09:00:02', 1.50, '2024-12-22 09:01:49', '闽A88888'),
(21, '2024-12-23 10:15:17', 1.50, '2024-12-23 10:17:04', '沪B69999'),
(22, '2024-12-24 11:30:31', 1.50, '2024-12-24 11:32:18', '辽BSZ889'),
(23, '2024-12-25 12:45:46', 1.50, '2024-12-25 12:47:33', '苏M6L756'),
(24, '2024-12-26 14:00:00', 1.50, '2024-12-26 14:01:47', '粤B6Y889'),
(25, '2024-12-27 15:15:15', 1.50, '2024-12-27 15:17:02', '京A55069'),
(26, '2024-12-28 16:30:29', 1.50, '2024-12-28 16:32:16', '沪KB3517'),
(27, '2024-12-29 17:45:44', 1.50, '2024-12-29 17:47:31', '鲁P54250'),
(28, '2024-12-30 19:00:58', 1.50, '2024-12-30 19:02:45', '辽JB2368');
(29, '2024-12-03 18:15:00', 2.50, '2024-12-03 18:45:00', '苏M6L756'),
(30, '2024-12-04 18:30:00', 2.75, '2024-12-04 19:00:00', '沪KB3517'),
(31, '2024-12-05 18:45:00', 3.00, '2024-12-05 19:15:00', '辽JB2368'),
(32, '2024-12-06 19:00:00', 2.50, '2024-12-06 19:30:00', '粤B6Y889'),
(33, '2024-12-07 19:15:00', 2.75, '2024-12-07 19:45:00', '京A55069'),
(34, '2024-12-08 19:30:00', 3.00, '2024-12-08 20:00:00', '苏E05EV8'),
(35, '2024-12-09 19:45:00', 2.50, '2024-12-09 20:15:00', '辽BSZ889'),
(36, '2024-12-10 20:00:00', 2.75, '2024-12-10 20:30:00', '冀A636P8'),
(37, '2024-12-11 20:15:00', 3.00, '2024-12-11 20:45:00', '浙A66666'),
(38, '2024-12-12 20:30:00', 2.50, '2024-12-12 21:00:00', '鲁P54250'),
(39, '2024-12-13 18:20:00', 2.00, '2024-12-13 18:50:00', '苏E05EV8'),
(40, '2024-12-14 18:35:00', 2.25, '2024-12-14 19:05:00', '京A63708'),
(41, '2024-12-15 18:50:00', 2.50, '2024-12-15 19:20:00', '沪KR9888');
-- IC卡信息表初始化脚本:
INSERT IGNORE INTO icinformation (user_id, card_number, password, balance)
VALUES
(1, '12345678', 'pass123', 100.0),
(2, '23456789', 'pass234', 150.0),
(3, '34567890', 'pass345', 200.0),
(4, '45678901', 'pass456', 120.0),
(5, '56789012', 'pass567', 180.0),
(6, '67890123', 'pass678', 300.0),
(7, '78901234', 'pass789', 80.0),
(8, '89012345', 'pass890', 250.0),
(9, '90123456', 'pass901', 175.0),
(10, '01234567', 'pass012', 210.0),
(11, '12340123', 'pass1234', 190.0),
(12, '23451234', 'pass2345', 220.0),
(13, '34562345', 'pass3456', 280.0),
(14, '45673456', 'pass4567', 150.0),
(15, '56784567', 'pass5678', 200.0),
(16, '67895678', 'pass6789', 260.0),
(17, '78906789', 'pass7890', 175.0),
(18, '89017890', 'pass8901', 300.0),
(19, '90128901', 'pass9012', 180.0),
(20, '01239012', 'pass0123', 240.0),
(21, '12340123', 'pass1234', 200.0),
(22, '23451234', 'pass2345', 170.0),
(23, '34562345', 'pass3456', 280.0),
(24, '45673456', 'pass4567', 150.0),
(25, '56784567', 'pass5678', 200.0),
(26, '67895678', 'pass6789', 260.0),
(27, '78906789', 'pass7890', 175.0),
(28, '89017890', 'pass8901', 300.0),
(29, '90128901', 'pass9012', 180.0),
(30, '01239012', 'pass0123', 240.0);
-- 车位信息表初始化脚本:
INSERT INTO parkinglot.parkingspotinformation
(parking_spot_id, spot_type, occupancy_status, location, fee_standard)
VALUES
(1, '正常使用', 1, 'A1', 1.50),
(2, '正常使用', 0, 'A2', 1.50),
(3, '正常使用', 0, 'A3', 1.50),
(4, '正常使用', 0, 'A4', 1.50),
(5, '正常使用', 0, 'A5', 1.50),
(6, '正常使用', 0, 'A6', 1.50),
(7, '正常使用', 0, 'B1', 1.50),
(8, '正常使用', 0, 'B2', 1.50),
(9, '正常使用', 0, 'B3', 1.50),
(10, '正常使用', 0, 'B4', 1.50),
(11, '正常使用', 0, 'B5', 1.50),
(12, '正常使用', 0, 'B6', 1.50),
(13, '正常使用', 0, 'C1', 1.50),
(14, '正常使用', 0, 'C2', 1.50),
(15, '正常使用', 0, 'C3', 1.50),
(16, '正常使用', 0, 'C4', 1.50),
(17, '正常使用', 0, 'C5', 1.50),
(18, '正常使用', 0, 'C6', 1.50),
(19, '正常使用', 0, 'D1', 1.50),
(20, '正常使用', 0, 'D2', 1.50),
(21, '正常使用', 0, 'D3', 1.50),
(22, '正常使用', 0, 'D4', 1.50),
(23, '正常使用', 0, 'D5', 1.50),
(24, '正常使用', 0, 'D6', 1.50),
(25, '正常使用', 0, 'E1', 1.50),
(26, '正常使用', 0, 'E2', 1.50),
(27, '正常使用', 0, 'E3', 1.50),
(28, '正常使用', 0, 'E4', 1.50),
(29, '正常使用', 0, 'E5', 1.50),
(30, '正常使用', 0, 'E6', 1.50),
(31, '正常使用', 0, 'F1', 1.50);

@ -0,0 +1,147 @@
-- 查找最新停车记录
SELECT *
FROM parking_record_view
WHERE car_license = ?
ORDER BY start_time DESC
LIMIT 1;
-- 查询插入新的停车记录所需信息
SELECT *
FROM (
SELECT *
FROM vehicleinformation
WHERE car_license = ?
) vi
INNER JOIN userinformation ui ON vi.user_id = ui.user_id
INNER JOIN parkingspotinformation psi ON ui.parking_spot_id = psi.parking_spot_id;
-- 选出停车费消费总额前5名的用户
SELECT user_name, total_parking_fees
FROM userparkingtotalfees
ORDER BY total_parking_fees DESC
LIMIT 5;
SELECT DATE(start_time) AS date, SUM(parking_fee) AS total_income
FROM parkingrecord
WHERE start_time >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
GROUP BY DATE(start_time)
ORDER BY DATE(start_time);
()
SELECT COUNT(*)
FROM parkingspotinformation psi
WHERE NOT EXISTS (
SELECT *
FROM parkingrecord pr
WHERE pr.parking_spot_id = psi.parking_spot_id
AND TIME(pr.start_time) BETWEEN '18:00:00' AND '21:00:00); '
-- 分析一周内一天不同时刻中停车位的平均使用时长
SELECT
HOUR(pr.start_time) AS Hour,
AVG(TIMESTAMPDIFF(MINUTE, pr.start_time, pr.end_time)) as AverageParkingMinutes
FROM parkingrecord pr
WHERE
YEARWEEK(pr.start_time, 1) = YEARWEEK(CURDATE(), 1)
GROUP BY Hour
ORDER BY Hour;
-- 查看目前小区的所有车辆和其拥有者的信息
SELECT * FROM vehicleuserview
-- 根据车牌号,品牌,型号进行检索
SELECT * FROM vehicleuserview
WHERE
car_license LIKE %?%
AND brand=?
AND model=?
AND address LIKE ?%
-- 通过user_id连接parkingspotinformation和userinformation表对用户车位信息进行查询
SELECT *FROM parkingspotinformation INNER JOIN userinformation ON parkingspotinformation.parking_spot_id =userinformation.parking_spot_id
WHERE userinformation.user_id = ?;
-- 通过user_id连接parkingrecord和userinformation表对用户停车记录进行查询并以start_time为基准进行排序
SELECT *
FROM parkingrecord
INNER JOIN userinformation ON parkingrecord.parking_spot_id = userinformation.parking_spot_id
WHERE userinformation.user_id = ?
ORDER BY start_time DESC;
-- 查询所有车位的情况
SELECT * FROM parkingspotinformation
-- 查看所有的停车记录及筛选所需记录
SELECT * FROM parking_record_view
WHERE car_license = ?
AND location = ?
AND start_time >= ?
AND end_time <= ?
ORDER BY start_time DESC
-- 展示用户信息
select *
from userinformation
-- 搜索相关用户
select *
from userinformation
where name like '%?'
and parking_spot_id=?
and address=?
-- 排序按照user_id、name、parking_spot_id
select *
from userinformation
order by user_id
select *
from userinformation
order by name
select *
from userinformation
order by parking_spot_id
-- 统计用户数量
select count(*)
as total_user
from userinformation
-- 按照性别统计
select gender, count(*)
as gender_count
from userinformation
group by gender
-- 按照用户类型统计
select user_type,count(*)
as user_count
from userinformation
group by user_type
-- 查看特定用户对应的车辆信息
select v.car_license,v.user_id,v.brand,v.model
from vehicleinformation v
join userinformation u on v.user_id=u.user_id
where u.user_id=?
order by v.car_license
-- 查看特定用户对应的车位信息
select p.parking_spot_id,p.spot_type,p.occupancy_status,p.location,p.fee_standard
from userinformation u
left join parkingspotinformation p on u.parking_spot_id=p.parking_spot_id
where p.parking_spot_id=?
-- 查看特定用户对应的IC卡信息
select i.user_id,i.card_number,i.password,i.balance
from userinformation u
inner join icinformation i on u.user_id=i.user_id
where u.user_id=?
-- 通过user_id查询用户ic卡信息
SELECT *
FROM icinformation
WHERE user_id = ?;
-- 通过user_id查询用户的车辆信息
SELECT *
-- FROM vehicleinformation
WHERE user_id = ?
-- 通过user_id查询用户信息
SELECT *
FROM userinformation
WHERE user_id = ?
-- 通过user_id 使用EXISTS语句对时间处于start 和end之间的记录进行查询同时根据type为基准进行order排序
SELECT *
FROM parkingrecord r
WHERE EXISTS(
SELECT 1
FROM userinformation u
WHERE u.parking_spot_id = r.parking_spot_id AND u.user_id=?)
AND r.start_time>=? AND r.end_time<=?
ORDER BY "+type+" "+order+";
-- 通过spot和fee上下限对fee设定范围内的记录进行条件查询同时对其进行排序
SELECT *
FROM parkingrecord
WHERE parking_spot_id = ? AND parking_fee Between ? AND ?
ORDER BY "+type+" "+order+";

@ -0,0 +1,29 @@
-- 将停车位置为占用状态
UPDATE parkingspotinformation
SET occupancy_status = 1
WHERE parking_spot_id = ?
-- 更新停车记录的结束时间
UPDATE parkingrecord
SET end_time = ?
WHERE record_id = ?;
-- 修改用户信息
update userinformation
set name=?,telephone=?,user_type=?,parking_spot_id=?,address=?,gender=?
where user_id=?
-- 对指定user_id的用户记录进行更新
UPDATE userinformation SET name=?,gender=?, telephone=?, address=?WHERE user_id=?
-- 将特定车型的停车费用提高10%
UPDATE ParkingRecord pr
JOIN VehicleInformation vi ON pr.car_license = vi.car_license
JOIN ParkingSpotInformation psi ON pr.parking_spot_id = psi.parking_spot_id
SET pr.parking_fee = pr.parking_fee * 1.1
WHERE vi.brand = ?;
-- 将停车超过 6 小时的记录的停车费用增加 20%
UPDATE ParkingRecord
SET parking_fee = parking_fee * 1.2
WHERE TIMESTAMPDIFF(HOUR, start_time, end_time) > 6;
-- 更新停车记录的车辆信息
UPDATE ParkingRecord pr
JOIN VehicleInformation vi ON pr.car_license = vi.car_license
SET vi.brand = ?, vi.model = ?
WHERE pr.record_id = ?;
Loading…
Cancel
Save