How to get rid of the php wrapping on this sql query
问题 I have two tables. One is production table with posts and other is the collection of posts's views. Once a hour, all post views get grouped together and main production table gets updated. And post's views table gets truncated. My objective is to get this function into pure SQL, so I could run it inside database engine as scheduled event. SQL is my weakest point, and I can make it work with SELECT being inside one UPDATE. But if there are two UPDATE queries, then I need some sort of variable.