This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
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


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SUM using two attributes" Watch "SUM using two attributes" New topic
Author

SUM using two attributes

rahull agarwal
Ranch Hand

Joined: Dec 20, 2010
Posts: 31
Hi,

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
Bartender

Joined: Oct 14, 2005
Posts: 19359
    
  10

That depends on what database you are using. Here is a page which gives examples for a couple of the more common databases.
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: SUM using two attributes