Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql query

Status
Not open for further replies.

hugoscp1

Technical User
Joined
Aug 27, 2018
Messages
5
Location
PT
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
 
your SELECT statement variables are the same on both queries, hence the output will have the same columns.

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
Thank you for the reply. Please tell me what I should do. Rewrite the code for me please. If I delete a column field will it work?
Please help me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top