use of case ... when ... end ...
Requirements: When checking the database, if the shareholder_type field is 1, the output type is enterprise, and the shareholder_type field is 2, then the output type is personal, otherwise output
SELECT shareholder_name AS name,proportion AS category,
(CASE
WHEN shareholder_type = '1' THEN '企业'
WHEN shareholder_type = '2' THEN '个人'
ELSE '其他' END ) AS type
FROM
d_ownership_overview
WHERE 1=1
<if test="enterpriseName != null and enterpriseName != ''">
AND enterprise_name = #{enterpriseName}
</if>
Simple Case function, more concise
Output male when sex is 1, output female when it is 2, otherwise output
CASE sex
WHEN '1' THEN 'Male'
WHEN '2' THEN 'Female'
ELSE 'Other' END
Case search function, more flexible
CASE WHEN sex = ‘1’ THEN ‘男’
WHEN sex = ‘2’ THEN ‘女’
ELSE ‘其他’ END
Note: (It has nothing to do with the above)
nohup.out is the monitoring log file on the server
tail -1000 nohup.out (view the last 1000 lines of log text)
tail -f nohup.out (monitoring log printing)