简体   繁体   English

SQL触发器还是其他?

[英]SQL Trigger or something else?

How can I use trigger to update my table that have status column that is now set on unknown . 我如何使用触发器来更新我的表,该表的状态列现在设置为unknown How can I change this to "open" or "close" depending on the "time_spent" and "time_available" in the table? 如何根据表中的“ time_spent”和“ time_available”将其更改为“ open”或“ close”? The status should change automatically when "time_spent" = "time_available". 当“ 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

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

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