MySQL Forums
Forum List  »  PHP

SQL newbie question
Posted by: Rich Bernstein
Date: August 27, 2020 05:37PM

Hi, what I want to do is to create more than one a single thing in each case statement. For example, when risk is medium I'd like to not only divide w.w2_wages/2, but I'd also like to total the e.w2_wages, using something like this total_mid_risk=total_mid_risk+e.w2_wages. Basically I want to sum all of the w2_wages for each of the 3 groups; low risk, mid risk, and high risk. Is there anyway to do this without using a stored procedure? Can "then" have multiple statements?



SELECT e.employee, e.employee_title, e.w2_wages, t.risk,
CASE
WHEN risk='low' THEN e.w2_wages
WHEN risk='medium' THEN e.w2_wages*.5
ELSE 0
END as qualified
FROM employees as e, titles as t
WHERE e.email='$email' AND e.campaign= '$_SESSION[campaign]'
AND t.email='$email' AND t.campaign= '$_SESSION[campaign]'
AND e.employee_title=t.title
ORDER BY e.employee

Options: ReplyQuote


Subject
Written By
Posted
SQL newbie question
August 27, 2020 05:37PM
August 28, 2020 09:52AM


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.