Mysql 如何每天运行自动查询

Mysql 如何每天运行自动查询,mysql,sql,Mysql,Sql,我有一个名为trans的表,它的结构如下 # Name Type Collation Attributes Null Default Extra Action 1 user_id int(11) No None Change Change Drop Drop Browse distinct values Browse distinct values Primary Primary Unique Unique I

我有一个名为trans的表,它的结构如下

#   Name    Type    Collation   Attributes  Null    Default Extra   Action
 1  user_id int(11)         No  None    Change Change    Drop Drop   Browse distinct values Browse distinct values   Primary Primary     Unique Unique   Index Index    Spatial Spatial Show more actions More
 2  amount  decimal(16,8)   No  None     Change Change   Drop Drop   Browse distinct values Browse distinct values   Primary Primary     Unique Unique   Index Index    Spatial Spatial Show more actions More
 3  aff int(11)             No  0        Change Change   Drop Drop   Browse distinct values Browse distinct values   Primary Primary     Unique Unique   Index Index    Spatial Spatial Show more actions More
 4  jackpot int(11)         No  0        Change Change   Drop Drop   Browse distinct values Browse distinct values   Primary Primary     Unique Unique   Index Index    Spatial Spatial Show more actions More
 5  paidout int(11)         No  0        Change Change   Drop Drop   Browse distinct values Browse distinct values   Primary Primary     Unique Unique   Index Index    Spatial Spatial Show more actions More
 6  type    int(11)         No  0        Change Change   Drop Drop   Browse distinct values Browse distinct values   Primary Primary     Unique Unique   Index Index    Spatial Spatial Show more actions More
 7  created timestamp       No  CURRENT_TIMESTAMP        Change Change   Drop Drop   Browse distinct values Browse distinct values   Primary Primary     Unique Unique   Index Index    Spatial Spatial Show more actions More
此表不断增加数百万行,每隔几天,必须折叠此表以执行此查询:

SELECT user_id,paidout,sum(amount) as amount FROM trans GROUP BY user_id,paidout
然后,我将此查询的结果以sql格式导出到我的计算机

然后清空trans表,然后将从上面的查询导出的sql文件导入trans


我的问题是,是否有任何方法可以使此过程每天自动运行?

您真的需要使用MySQL和Microsoft SQL Server来执行此操作,还是您错过了一个错误的标签?是的。阅读有关crontab和bash脚本的内容。如果是MySQL,则可以使用,如果是MS sql server,则可以使用sql server代理。为什么不简单地更新字段,而不是添加一个完整的新行并在之后对其进行分组?@chresse如果您能建议我确切的查询,我会更新,但我找不到其他方法来执行此操作。