--select t.*,rowid from act t where an=2024 and luna = 6 order by dataact, nract, cod;

/*select t.*,rowid from act t where an=2024 and luna = 3 and cod in (
select cod from
(with select_data as
(select distinct a.cod, a.dataact, a.nract, b.cod as codb from
(select distinct dataact, nract, suma, cod, explicatia4 from act where an=2024 and luna = 2 and sters = 0 and explicatia4 = 'IMPORT BIZ') a join 
(select distinct dataact, nract, suma, cod, explicatia4 from act where an=2024 and luna = 2 and sters = 0 and explicatia4 is null) b on (a.dataact = b.dataact and a.nract = b.nract and a.suma = b.suma)
)
select cod from select_data
union 
select codb from select_data))
order by dataact, nract, cod;*/



select an, luna, nract, dataact, scd, ascd, scc, ascc, suma, explicatia4, sters, id_utils, dataoras, cod from
(select an, luna, nract, dataact, scd, ascd, scc, ascc, suma, explicatia4, sters, id_utils, dataoras, cod from act
union 
select an, luna, nract, dataact, scd, ascd, scc, ascc, suma, explicatia4, 0 as sters, 0 as id_utils, null as dataoras, cod from act_imp_2024)
where an=2024 and luna = 10 and cod in (
select cod from
(with select_data as
(select distinct a.cod, a.dataact, a.nract, b.cod as codb from
(select distinct dataact, nract, suma, cod, explicatia4 from act_imp_2024 where an=2024 and luna = 10 ) a join 
(select distinct dataact, nract, suma, cod, explicatia4 from act where an=2024 and luna = 10 and sters = 0 and explicatia4 is null) b on (a.dataact = b.dataact and a.nract = b.nract and a.suma = b.suma)
)
select cod from select_data
union 
select codb from select_data))
order by dataact, nract, cod, suma;

