如何编写SQL查询,我有一个名为ACC_REQUEST的表?
表格中有一栏名为REQUEST_STATUS,其值为'待定','撤回','已完成
如果请求状态值=' pending,则从ACC_APPROVAL中选择approver_name,否则选择请求状态
答案 0 :(得分:1)
答案 1 :(得分:1)
像
这样的东西SELECT
CASE
WHEN ACC_REQUEST.REQUEST_STATUS = 'pending' THEN ACC_APPROVAL.APPROVER_NAME
ELSE ACC_REQUEST.REQUEST_STATUS
END as [put the name you wish for output column here, no square brackets]
FROM ACC_REQUEST
INNER JOIN ACC_APPROVAL ON [I'm assuming some kind of join condition here]