我需要检查一个值是否大于其他每个值。
目前我有这个查询,但它只检查该值是否大于其他所有值:
IF (SELECT SUM(`price`) AS '14'
from data
where sale = 14) > (
SELECT SUM(`price`) AS 'x14'
from data where sale != 14)
THEN SET New.price=1.99;
虽然我需要它来检查销售(14)相关是否大于(15)且大于(16)..
答案 0 :(得分:1)
//DECLARE price_1 and 2 first
SELECT SUM(`price`) INTO price_1 from data where sale = 14 ;
SELECT MAX(price_others) INTO max_price FROM
(
SELECT SUM(`price`) as price_others, sale FROM data
where sale != 14 GROUP BY sale
) TMP ;
IF price_1 > max_price THEN
SET New.price=1.99;
END IF ;