File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes SUM using two attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SUM using two attributes" Watch "SUM using two attributes" New topic

SUM using two attributes

rahull agarwal
Ranch Hand

Joined: Dec 20, 2010
Posts: 31

My table has two columns amount and amountEstimated.

I would like to get a sum of the money using following logic.

If (amount == null) use amountEstimated
Else use amount.

How do I write a SQL for this?

Thanks so much for your help
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

That depends on what database you are using. Here is a page which gives examples for a couple of the more common databases.
I agree. Here's the link:
subject: SUM using two attributes
It's not a secret anymore!