mysql process control function

if function: if else results

SELECT IF(10<5,'大','小'); #第一个表达式为真则返回第二个参数否则返回第三个
#案例:
SELECT 
    last_name,
    commission_pct,
    IF(commission_pct IS NULL,'没奖金','有奖金')
FROM 
    employees;

The effect is similar to switch case: case function
# Case: Query wages department number 30, whose salary is 1.1 times; 40,1.2 times; 50,1.3 times; in other sectors of the original wage

SELECT salary AS 原始工资,department_id,

CASE department_id 
WHEN 30 THEN salary*1.1
WHEN 40 THEN salary*1.2
WHEN 50 THEN salary*1.3
ELSE salary     #相当于switch中的default:
END  AS  新工资 #结束
FROM employees;

Use case 2:; similar to multiple if, after then the value displayed is not added; if it is an expression then add
the case of wages of employees of the query: Case #

SELECT 
    salary,
    CASE
    WHEN salary >20000 THEN 'a'
    WHEN salary >15000 THEN 'b'
    WHEN salary >10000 THEN 'c'
    ELSE 'd'
    END AS 等级
FROM 
    employees;

Guess you like

Origin blog.51cto.com/14437184/2435964