简体   繁体   中英

SQL Trigger or something else?

How can I use trigger to update my table that have status column that is now set on unknown . How can I change this to "open" or "close" depending on the "time_spent" and "time_available" in the table? The status should change automatically when "time_spent" = "time_available".

You don't need a trigger. In fact, you don't even need to store this column. An easier approach would be to calculate it on the fly when you query the table:

SELECT *, CASE time_spent WHEN time_available THEN 'close' ELSE 'open' END
FROM   my_table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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