Saturday, April 21, 2012

Get sum of row in sql


CREATE TABLE EmployeeSalary
(
      ID INT PRIMARY KEY NOT NULL,
      NAME varchar(50),
      BASIC INT,
      HRA INT,
      BONUS INT
)

INSERT INTO EmployeeSalary(ID,NAME,BASIC,HRA,BONUS) values (1001,'Manish Agrahari',1000,500,200);

INSERT INTO EmployeeSalary(ID,NAME,BASIC,HRA,BONUS) values (1002,'Amit Singh',1000,500,200);

INSERT INTO EmployeeSalary(ID,NAME,BASIC,HRA,BONUS) values (1003,'Bill Gates',2000,800,300);

INSERT INTO EmployeeSalary(ID,NAME,BASIC,HRA,BONUS) VALUES (1004,'Raju Rastogi',2000,800,500);


SELECT * FROM EmployeeSalary



 
SELECT ID,NAME, BASIC,HRA,BONUS,(BASIC+HRA+BONUS)as Total_Salary
FROM EmployeeSalary



0 comments: