user3787029
user3787029

Reputation: 11

MySQL Triggers by dividing a number and then floor it

Given that I have this database structure.

Table: watchcount

uid      steamID         sessionid       watchcount            items
1       234234234        1232432            634                 0

I'd like to change column items automatically once watchcount gets updated. After watchcount has been divided by 60, floor the value so that it displays as an integer. Like this:

watchcount            items
634                   10 

Upvotes: 0

Views: 194

Answers (1)

Fabricator
Fabricator

Reputation: 12772

Here you go:

create trigger update_items 
before update on watchcount 
for each row 
set new.items = floor(new.watchcount/60);

doc

Upvotes: 1

Related Questions