MYSQL QUERY 如果存在则获取该特定列值并与新值进行比较

MYSQL QUERY if exists then get that specific column value and compare with new value

我正在尝试将新值与基于 SQL 语句的数据中的现有值进行比较,即转到 table 获取特定值并检查该值是否大于新值然后更新其他一些 table,否则什么都不做。

我的问题是我无法将查询值转换为字符串以在 if 语句中进行比较。

我的代码:

IF (EXISTS (SELECT * FROM table_1 WHERE   Id =NEW.Id and  time = NEW.time ORDER BY price ASC LIMIT 1)) THEN  

        IF (price <  NEW.price) THEN
//----------^^^^^^----------------- there is one column in table_1 not able to convert it to string to check in if statement///

            UPDATE historical SET low_price = NEW.price  WHERE  id =NEW.Id and date_time = NEW.time;  

        END IF;
    END IF;

如果价格是table_1中的一列,您可以将第二个if条件移动到第一个if条件。[​​=11=]

IF (EXISTS (SELECT * FROM table_1 WHERE   Id =NEW.Id and  time = NEW.time and price <  NEW.price ORDER BY price ASC LIMIT 1)) THEN  

        UPDATE historical SET low_price = NEW.price  WHERE  id =NEW.Id and date_time = NEW.time;  

END IF;