This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes SQL to update column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL to update column" Watch "SQL to update column" New topic
Author

SQL to update column

Raj Ohadi
Ranch Hand

Joined: Jun 30, 2006
Posts: 316
I have a table with following columns:

id(PK), name, score_1, score_2, score_3, rating

First I have the data for all columns EXCEPT rating. Then I want to update "rating" for each row using this rule

if (score_1 + score_2 + score_3) > 90: rating = A
if it > 80 but < 90 : rating =B
...

How to write this sql ?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32635
    
215

Raj,
You would need update statements. The easiest way to do this is to have one update statement for each letter grade. Try write an update statement for the first one and post here if you get stuck.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL to update column
 
It's not a secret anymore!