MySQL Forums
Forum List  »  Newbie

Re: Math in MySQL - Newbie Question
Posted by: Felix Geerinckx
Date: June 01, 2005 07:42AM

robertth wrote:

> My question is very simple right now I have 4 fields - monthpay - annualpay - depositpay and
> totalorder.
>
> What I'm trying to do is total the monthpayand annualpay (one of which will be 0 ) and then
> subtract the depositpay and have the results go into the totalpay field.

USE test;
DROP TABLE IF EXISTS payroll;
CREATE TABLE payroll (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
monthpay DECIMAL(10,2) NOT NULL DEFAULT 0.00,
annualpay DECIMAL(10,2) NOT NULL DEFAULT 0.00,
depositpay DECIMAL(10,2) NOT NULL DEFAULT 0.00,
totalpay DECIMAL(10,2) NOT NULL DEFAULT 0.00
);

INSERT INTO payroll (monthpay, annualpay, depositpay) VALUES
(100.00, 0.00, 40.00),
(0.00, 1500.00, 180.00);

UPDATE payroll
SET totalpay = monthpay + annualpay - depositpay;

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
Re: Math in MySQL - Newbie Question
June 01, 2005 07:42AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.