We help IT Professionals succeed at work.

Multiple functions in SQL select statement

Tina K
Tina K asked
on
125 Views
Last Modified: 2017-03-07
For some reason, this really has me stumped.  I'm trying to retrieve the max transaction id from the inventory_transaction table, but also need to sum up some costs.  As soon as I start adding any of the costs, no matter how I do it, the max(inventory_trans) fails and I get a record for each different cost.

Example - this works:

this one works
This doesn't:  I get 151 records, rather than the max:

not
Also doesn't work:

also not
Any help appreciated!
Comment
Watch Question

Scott PletcherSenior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
SELECT part_id, MAX(...), SUM(ACT_BURDEN_COST + ...) AS act_cost
FROM ...
WHERE ...
GROUP BY part_id
Tina KSystems Specialist

Author

Commented:
Hi Scott -
Gave that a try and get the same result of multiple records:

not-working-III.JPG
Senior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Tina KSystems Specialist

Author

Commented:
That did the trick Scott!  Thanks so much!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions