1

AM NEW TO MYSQL... HELP ME TO SORT OUT THIS...

I have a result like

 NO,     TYPE,  FEE_AMT
'2156', 'FTP2', 100.00
'2156', 'FTP4', 200.00
'2156', 'FTP5', 100.00
'2156', 'FTP6', 100.00
'2156', 'FTP3', 100.00

I want to sum all FEE_AMT, in which if the type='FTP5' I want to square the respective FEE_AMT and then add... I have tried sum(fee_amt) only...

EXPECTED OUTPUT IS: 10,500...


edit

100+200+(100*100)+100+100

I WANT TO SQUARE THE FEE AMOUNT IF FEE TYPE='FTP5'

THANKS IN ADVANCE... :)

2
  • Can you show us a reproducible sample and output? I don't see how you're getting 10,500 from your question. Do you want the sum of the squares, or the square of the sum? Commented Dec 18, 2015 at 6:08
  • Mr Tim... Please see my edited question... Thanks for your response first of all... Commented Dec 18, 2015 at 6:13

2 Answers 2

2
SELECT SUM(
    CASE WHEN TYPE='FTP5' THEN FEE_AMT*FEE_AMT ELSE FEE_AMT END) AS FeeSum
FROM yourTable
Sign up to request clarification or add additional context in comments.

1 Comment

Glad to help. Have a look here if you want to see a really ugly query.
0

SELECT SUM( if(TYPE='FTP5',FEE_AMT*FEE_AMT,FEE_AMT)) AS FeeSum FROM yourTable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.