将标量查询结果传递给coalesce

时间:2010-03-19 09:21:33

标签: mysql

如何将标量[单行,单值]查询的结果传递给合并?我试图选择优先级(到目前为止表中最大的优先级)+ 1. [0如果它是第一行。]

create trigger priority_SuperRuleSamples before insert on SuperRuleSamples 
FOR EACH ROW 
  SET NEW.Priority=coalesce(NEW.Priority, 
   coalesce(
   select Priority from SuperRuleSamples order by Priority desc limit 1, 
   -1
   )+1
  )

1 个答案:

答案 0 :(得分:0)

您的查询中似乎存在括号问题。你能试试吗?


create trigger priority_SuperRuleSamples before insert on SuperRuleSamples 
FOR EACH ROW 
  SET NEW.Priority=coalesce(NEW.Priority, 
   coalesce(
    (select Priority from SuperRuleSamples order by Priority desc limit 1), 
   -1
   )+1
  )