MySQL 删除当前日期之后的行并将它们转移到另一个 table
MySQL to remove rows past the current date and transfer them to another table
我的任务是为我的项目创建健身房系统的数据库,我需要帮助了解我的程序应该使用什么 MySQL 查询。
第一个查询:删除 TBL_ACTIVEMEMBER 中 END 列日期晚于当前日期的行。
第二个查询:将删除的行传输并插入另一个 table,即 TBL_INACTIVEMEMBER。
这些是我的 table:
- TBL_ACTIVEMEMBER:
+------+---------+--------+----------+----------+------------+------------+
| AMID | GYMID | INSTID | TYPE | TERM | START | END |
+------+---------+--------+----------+----------+------------+------------+
| 1 | 2021001 | 4502 | Gold | 3 Months | 2021-12-18 | 2022-03-18 |
| 2 | 2021003 | 4504 | Platinum | 3 Months | 2021-12-13 | 2022-03-13 |
| 3 | 2021002 | 4502 | Silver | 3 Months | 2022-01-15 | 2022-04-15 |
| 4 | 2021004 | 4502 | Platinum | 5 Months | 2021-12-25 | 2022-05-25 |
| 5 | 2021006 | 4503 | Silver | 5 Months | 2021-12-18 | 2022-05-18 |
| 6 | 2021007 | 4502 | Silver | 1 Month | 2021-12-24 | 2022-01-24 |
| 7 | 2021008 | 4501 | Gold | 3 Months | 2021-12-18 | 2022-03-18 |
| 8 | 2021008 | 4503 | Platinum | 1 Month | 2021-12-12 | 2022-01-12 |
| 9 | 2021009 | 4502 | Silver | 3 Months | 2022-01-08 | 2022-04-08 |
+------+---------+--------+----------+----------+------------+------------+
- TBL_INACTIVEMEMBER:
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| INAMID| int(11) | NO | PRI | NULL | auto_increment |
| GYMID | int(11) | YES | | NULL | |
| END | date | NO | | NULL | |
+-------+---------+------+-----+---------+----------------+
INSERT INTO TBL_INACTIVEMEMBER (Column1, Column2, ColumnN)
SELECT * FROM TBL_ACTIVEMEMBER where END < CURRENT_TIMESTAMP();
这会将所需的值插入 table TBL_INACTIVEMEMBER
。根据需要更改列名。
现在从 table TBL_ACTIVEMEMBER
,
中删除非活动值
DELETE FROM TBL_ACTIVEMEMBER WHERE END < CURRENT_TIMESTAMP()
我的任务是为我的项目创建健身房系统的数据库,我需要帮助了解我的程序应该使用什么 MySQL 查询。
第一个查询:删除 TBL_ACTIVEMEMBER 中 END 列日期晚于当前日期的行。
第二个查询:将删除的行传输并插入另一个 table,即 TBL_INACTIVEMEMBER。
这些是我的 table:
- TBL_ACTIVEMEMBER:
+------+---------+--------+----------+----------+------------+------------+ | AMID | GYMID | INSTID | TYPE | TERM | START | END | +------+---------+--------+----------+----------+------------+------------+ | 1 | 2021001 | 4502 | Gold | 3 Months | 2021-12-18 | 2022-03-18 | | 2 | 2021003 | 4504 | Platinum | 3 Months | 2021-12-13 | 2022-03-13 | | 3 | 2021002 | 4502 | Silver | 3 Months | 2022-01-15 | 2022-04-15 | | 4 | 2021004 | 4502 | Platinum | 5 Months | 2021-12-25 | 2022-05-25 | | 5 | 2021006 | 4503 | Silver | 5 Months | 2021-12-18 | 2022-05-18 | | 6 | 2021007 | 4502 | Silver | 1 Month | 2021-12-24 | 2022-01-24 | | 7 | 2021008 | 4501 | Gold | 3 Months | 2021-12-18 | 2022-03-18 | | 8 | 2021008 | 4503 | Platinum | 1 Month | 2021-12-12 | 2022-01-12 | | 9 | 2021009 | 4502 | Silver | 3 Months | 2022-01-08 | 2022-04-08 | +------+---------+--------+----------+----------+------------+------------+
- TBL_INACTIVEMEMBER:
+-------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+----------------+ | INAMID| int(11) | NO | PRI | NULL | auto_increment | | GYMID | int(11) | YES | | NULL | | | END | date | NO | | NULL | | +-------+---------+------+-----+---------+----------------+
INSERT INTO TBL_INACTIVEMEMBER (Column1, Column2, ColumnN)
SELECT * FROM TBL_ACTIVEMEMBER where END < CURRENT_TIMESTAMP();
这会将所需的值插入 table TBL_INACTIVEMEMBER
。根据需要更改列名。
现在从 table TBL_ACTIVEMEMBER
,
DELETE FROM TBL_ACTIVEMEMBER WHERE END < CURRENT_TIMESTAMP()