Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can any database do math?

Tags:

sql

database

math

Can databases (MySQL in particular, any SQL--MS, Oracle, Postgres--in general) do mass updates, and figure out on their own what the new value should be? Say for example I've got a database with information about a bunch of computers, and all of these computers have drives of various sizes--anywhere from 20 to 250 GB. Then one day we upgrade every single computer by adding a 120 GB hard drive. Is there a way to say something like

update computers set total_disk_space = (whatever that row's current total_disk_space is plus 120)
like image 998
user14701 Avatar asked Apr 01 '26 13:04

user14701


2 Answers

For the entire Table then:

Update Computers 
Set Total_Disk_Space = Total_Disk_Space + 120;

If, you only want to update certain ones, then you'd need filters, for example:

Update Computers
Set Total_Disk_Space = Total_Disk_Space + 120
Where PurchaseDate BETWEEN '1/1/2008' AND GETDATE();
like image 156
Stephen Wrighton Avatar answered Apr 03 '26 02:04

Stephen Wrighton


Yeah:

update computers set total_disk_space = total_disk_space + 120;
like image 37
Tom Leys Avatar answered Apr 03 '26 02:04

Tom Leys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!