id | first_name | last_name | role_id
角色\u id SELECT语句 我可以这样做:
SELECT users.*, ( if(role_id = 1, roleName), if(role_id = 2, roleName2), if(role_id = 3, roleName3)) AS roleName ) ORDER BY roleName DESC
CASE 表达式:
CASE
SELECT *, CASE role_id WHEN 1 THEN 'roleName1' WHEN 2 THEN 'roleName2' WHEN 3 THEN 'roleName3' END AS roleName FROM users ORDER BY roleName DESC
role_id ELT()
role_id
ELT()
SELECT *, ELT(role_id, 'roleName1', 'roleName2', 'roleName3') AS roleName FROM users ORDER BY roleName DESC