×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

sql query

sql query

sql query

(OP)
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

RE: sql query

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


RE: sql query

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close