I try this query:
select t.clndhf, t.ciusmd, t.nmismd, SUM(Quantity) as Num_Products
from
(
select clndhf, ciusmd, nmismd, sum(qtfdhf) as Quantity
from swapfilio.EESWPLFD join swapfilio.EESWPLFH
on SOCSLD = SOCSLH
and CODSLD = CODSLH
join swapfilio.gesmd
on SOCSLD = socsmd
and NIISLD = niismd
join swapfilio.gefhf
on niisld = artdhf
where dgrdhf >= SUBSTR(CHAR(CURRENT DATE, ISO), 1, 4) ||
SUBSTR(CHAR(CURRENT DATE, ISO), 6, 2) || '01'
and tpfdhf <> 'DD'
and ciusmd = '5064530'
group by clndhf, ciusmd, nmismd
) as t
group by t.clndhf, t.ciusmd, t.nmismd
and this query:
select clndhf, ciusmd, nmismd, sum(qtfdhf) as Quantity
from swapfilio.EESWPLFD join swapfilio.EESWPLFH
on SOCSLD = SOCSLH
and CODSLD = CODSLH
join swapfilio.gesmd
on SOCSLD = socsmd
and NIISLD = niismd
join swapfilio.gefhf
on niisld = artdhf
where dgrdhf >= SUBSTR(CHAR(CURRENT DATE, ISO), 1, 4) ||
SUBSTR(CHAR(CURRENT DATE, ISO), 6, 2) || '01'
and tpfdhf <> 'DD'
and ciusmd = '5064530'
group by clndhf, ciusmd, nmismd
and the result is the same
CLNDHF CIUSMD NMISMD QUANTITY
1 5064530 AERIUS 5 MG COMP.OROD X20 22.000
2 5064530 AERIUS 5 MG COMP.OROD X20 176.000
24 5064530 AERIUS 5 MG COMP.OROD X20 44.000
35 5064530 AERIUS 5 MG COMP.OROD X20 11.000
38 5064530 AERIUS 5 MG COMP.OROD X20 110.000
and should give this result:
CLNDHF CIUSMD NMISMD QUANTITY
1 5064530 AERIUS 5 MG COMP.OROD X20 2
2 5064530 AERIUS 5 MG COMP.OROD X20 16
24 5064530 AERIUS 5 MG COMP.OROD X20 4
35 5064530 AERIUS 5 MG COMP.OROD X20 1
38 5064530 AERIUS 5 MG COMP.OROD X20 10
please help me
thank you
select t.clndhf, t.ciusmd, t.nmismd, SUM(Quantity) as Num_Products
from
(
select clndhf, ciusmd, nmismd, sum(qtfdhf) as Quantity
from swapfilio.EESWPLFD join swapfilio.EESWPLFH
on SOCSLD = SOCSLH
and CODSLD = CODSLH
join swapfilio.gesmd
on SOCSLD = socsmd
and NIISLD = niismd
join swapfilio.gefhf
on niisld = artdhf
where dgrdhf >= SUBSTR(CHAR(CURRENT DATE, ISO), 1, 4) ||
SUBSTR(CHAR(CURRENT DATE, ISO), 6, 2) || '01'
and tpfdhf <> 'DD'
and ciusmd = '5064530'
group by clndhf, ciusmd, nmismd
) as t
group by t.clndhf, t.ciusmd, t.nmismd
and this query:
select clndhf, ciusmd, nmismd, sum(qtfdhf) as Quantity
from swapfilio.EESWPLFD join swapfilio.EESWPLFH
on SOCSLD = SOCSLH
and CODSLD = CODSLH
join swapfilio.gesmd
on SOCSLD = socsmd
and NIISLD = niismd
join swapfilio.gefhf
on niisld = artdhf
where dgrdhf >= SUBSTR(CHAR(CURRENT DATE, ISO), 1, 4) ||
SUBSTR(CHAR(CURRENT DATE, ISO), 6, 2) || '01'
and tpfdhf <> 'DD'
and ciusmd = '5064530'
group by clndhf, ciusmd, nmismd
and the result is the same
CLNDHF CIUSMD NMISMD QUANTITY
1 5064530 AERIUS 5 MG COMP.OROD X20 22.000
2 5064530 AERIUS 5 MG COMP.OROD X20 176.000
24 5064530 AERIUS 5 MG COMP.OROD X20 44.000
35 5064530 AERIUS 5 MG COMP.OROD X20 11.000
38 5064530 AERIUS 5 MG COMP.OROD X20 110.000
and should give this result:
CLNDHF CIUSMD NMISMD QUANTITY
1 5064530 AERIUS 5 MG COMP.OROD X20 2
2 5064530 AERIUS 5 MG COMP.OROD X20 16
24 5064530 AERIUS 5 MG COMP.OROD X20 4
35 5064530 AERIUS 5 MG COMP.OROD X20 1
38 5064530 AERIUS 5 MG COMP.OROD X20 10
please help me
thank you