1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
with tmp (id, item, statut) as (
select 'DO1' as id, 'ITEM1' as item, 0 as statut from sysibm.sysdummy1
union all
select 'DO1', 'ITEM2', 1 from sysibm.sysdummy1
union all
select 'DO1', 'ITEM3', 0 from sysibm.sysdummy1
union all
select 'DO2', 'ITEM1', 1 from sysibm.sysdummy1
union all
select 'DO2', 'ITEM2', 1 from sysibm.sysdummy1
union all
select 'DO3', 'ITEM1', 0 from sysibm.sysdummy1
union all
select 'DO3', 'ITEM2', 0 from sysibm.sysdummy1
union all
select 'DO3', 'ITEM3', 0 from sysibm.sysdummy1)
SELECT *
FROM (SELECT id, COUNT(*) as cnt, SUM(statut) as cnt2 FROM tmp GROUP BY id ) as tmp2
WHERE cnt = cnt2; |
Partager