mysql example

# Employee names sorted by the first letter, and write the name of length

SELECT
    LENGTH(last_name),SUBSTR(last_name,1,1) AS 首字符

FROM
    employees
ORDER BY 
    首字符 ;

Direct alphabetical order

# Graded to job_id

SELECT
    job_id,
    CASE job_id
    WHEN 'AD_PRES' THEN 'A'
    WHEN 'ST_MAN' THEN 'B'
    WHEN 'IT_PROG' THEN 'C'
    WHEN 'SA_REP' THEN 'D'
    WHEN 'ST_CLERK' THEN 'E'
    END
FROM 
    employees

When there are no other cases, else should be omitted

Guess you like

Origin blog.51cto.com/14437184/2435971