Question:
I'm having some trouble with an SQL QUERY adding each column by 10%?
Philip
2010-07-16 19:40:54 UTC
So here's the question:

o Increase all employees’ salaries with the selected EEO-1 classification by 10%.

Okay, so I know how to select the employees by the EEO-1 classification in my database, but now that I have those selected how do I make it add each data by 10%? the sum() only adds a column together, But It's asking me to increase each individual value by 10%. What would be the correct query to this with?
Four answers:
Jim
2010-07-17 03:24:35 UTC
I don't see the structure for your database listed, so I am going to have to make some guesses, which could mean anything for you.

for simple tables,



UPDATE employees

SET salary=salary*(1+0.10)

WHERE employees.classification='EEO-1'



unless your classification is stored in some other table like HR (it usually is). in which case try something akin to



UPDATE employees

SET salary=salary*(1+0.10)

WHERE hr.classification='EEO-1' AND hr.employeeid=employees.employeeid



in mysql % is modulus and %% is a % character.



and don't you mean row instead of column? your data should be organized in rows instead of columns. that's probably where your trouble is.



I wrote up a more complicated multi-table update example with more of an HR view of a company at the link below. should be up in 15 minutes.
Satya
2010-07-20 01:42:16 UTC
Follow the Below Steps:

1. First execute the below query for evaluate the final result

Select empcode,Salary, Salary + ((Salary*10)/100) as NewSalary

From Employee where EEO='1'

2. If your satisfied with the result set then

Begin Transaction

Update Employee set Salary = Salary + ((Salary*10)/100)

Where EEO='1'

3. Check the data updated by using Select statement specified in Point 1. Once you are sure about data then Perform "Commit Transaction"
TheMadProfessor
2010-07-19 09:37:19 UTC
If you want to actually change the values in the database, Jim's answer is correct. If you want to merely display what the results of such an update would be (such as a management 'what-if' scenario) without actually changing anything, try this:



SELECT employee, (salary * 1.10) AS "New Salary" FROM employee
hyde
2016-10-19 08:11:28 UTC
attempt this: opt for call, Org id, e mail, Designation, (opt for t1.e mail from user_table t1 the place t1.[Org id] = t2.[Org id] and t1.Designation = 'Engineer') as New from user_table t2


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...