简体   繁体   English

删除MySQL表中的周末数据

[英]Deleting weekend data in MySQL table

I have some tables in MySQL db.我在 MySQL 数据库中有一些表。 My table has date as one of its columns and has data for last one year.我的表将日期作为其列之一,并包含过去一年的数据。 I want to delete the data of weekends since that is of no use to me.我想删除周末的数据,因为那对我没有用。 Is it possible to delete the weekend data from these db tables with an SQL query ?是否可以使用 SQL 查询从这些数据库表中删除周末数据?

Try using DAYOFWEEK :尝试使用DAYOFWEEK

DELETE
FROM yourTable
WHERE DAYOFWEEK(date_col) IN (1, 7);

The above query would target for deletion any record happening to fall on a Saturday (7) or Sunday (1).上述查询的目标是删除发生在星期六 (7) 或星期日 (1) 的任何记录。

There is inbuild function in mysql to find days of week. mysql 中有 inbuild 函数来查找星期几。

delete from table where DAYOFWEEK(date) in (1,7)

where 1 = Sunday, 7 = Saturday其中 1 = 星期日,7 = 星期六

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM