我有这个表,我需要一个查询,它返回每个tabla寄存器有多少UPDATE,INSERT和DELETE。
像...一样的东西。
| Tabla | # Of Insert's | # Of Delete's | # Of Update's
我不知道它是否清楚,#NoEnglishNativeSpeaker
答案 0 :(得分:3)
你可能正在寻找这样的东西:
select
Table,
sum(case when Operacion = 'INSERT' then 1 else 0 end),
sum(case when Operacion = 'DELETE' then 1 else 0 end),
sum(case when Operacion = 'UPDATE' then 1 else 0 end)
from
xxx
group by
Table
答案 1 :(得分:0)
你在寻找像这样的东西:
select a.tabla,a.insertCount,b.updateCount,c.deleteCount
from (select
Tabla,
count(*) as insertCount
from table
where Operation = 'INSERT'
group by
Tabla)a,
(select
Tabla,
count(*) as insertCount
from table
where Operation = 'UPDATE'
group by
Tabla)b,
(select
Tabla,
count(*) as deleteCount
from table
where Operation = 'DELETE'
group by
Tabla)c
where a.tabla=b.tabla and b.tabla=c.tabla