自我加入以避免分组

时间:2011-06-22 11:36:20

标签: mysql

以下查询按预期工作并向我显示我的触发器。

SELECT TRIGGER_SCHEMA, EVENT_OBJECT_TABLE,
IF(EVENT_MANIPULATION = 'UPDATE' AND ACTION_TIMING='BEFORE', TRIGGER_NAME, '') AS BEFORE_UPDATE,
IF(EVENT_MANIPULATION = 'UPDATE' AND ACTION_TIMING = 'AFTER', TRIGGER_NAME, '') AS AFTER_UPDATE,
IF(EVENT_MANIPULATION = 'INSERT' AND ACTION_TIMING='BEFORE', TRIGGER_NAME, '') AS BEFORE_INSERT,
IF(EVENT_MANIPULATION = 'INSERT' AND ACTION_TIMING = 'AFTER', TRIGGER_NAME, '') AS AFTER_INSERT,
IF(EVENT_MANIPULATION = 'DELETE' AND ACTION_TIMING='BEFORE', TRIGGER_NAME, '') AS BEFORE_DELETE,
IF(EVENT_MANIPULATION = 'DELETE' AND ACTION_TIMING = 'AFTER', TRIGGER_NAME, '') AS AFTER_DELETE
from information_schema.triggers ;

问题是如果我有3个AFTER触发器,它会显示在3个单独的行上。如何在同一行显示所有三个? 我尝试使用TRIGGER_SCHEMA,EVENT_OBJECT_TABLE进行分组 - 但它显示了预期触发器名称的空白值。

1 个答案:

答案 0 :(得分:0)

尝试做

COALESCE(IF(....))作为FinalColumn

可能会有多个插入/更新/删除触发器(或级联结果)影响您的结果。