我正在尝试基于我在内存中的i18n键订购一个查询。 所以我建立了这个查询:
SELECT "workflow_tasks".* FROM "workflow_tasks"
ORDER BY CASE
WHEN type='Workflow::Tasks::EmailCloseBrothersAboutPersonalDetailsChange' THEN 'Email Close Brothers'
WHEN type='Workflow::Tasks::CaptureFinanceProposal' THEN 'Record Finance Status'
WHEN type='Workflow::Tasks::SubmitCreditCheck' THEN 'Submit Credit Check'
WHEN type='Workflow::Tasks::UpdateDriverBankDetail' THEN 'Update Driver''s Bank Details'
WHEN type='Workflow::Tasks::UpdateDriverPersonalDetail' THEN 'Update Driver''s Personal Details'
WHEN type='Workflow::Tasks::ValidateInsuranceCertificate' THEN 'Validate Driver''s Insurance Certificate'
END
我希望它能根据THEN
除了ValidateInsuranceCertificate
位于UpdateDriverPersonalDetails
之前,顺序几乎是正确的。我一定误解了CASE
中ORDER BY
的用法:
答案 0 :(得分:1)
我猜你以某种方式没有完全匹配。我将从以下内容开始:
SELECT wf.*,
(CASE WHEN type = 'Workflow::Tasks::EmailCloseBrothersAboutPersonalDetailsChange' THEN 'Email Close Brothers'
WHEN type = 'Workflow::Tasks::CaptureFinanceProposal' THEN 'Record Finance Status'
WHEN type = 'Workflow::Tasks::SubmitCreditCheck' THEN 'Submit Credit Check'
WHEN type = 'Workflow::Tasks::UpdateDriverBankDetail' THEN 'Update Driver''s Bank Details'
WHEN type = 'Workflow::Tasks::UpdateDriverPersonalDetail' THEN 'Update Driver''s Personal Details'
WHEN type = 'Workflow::Tasks::ValidateInsuranceCertificate' THEN 'Validate Driver''s Insurance Certificate'
END) as sortkey
FROM "workflow_tasks" wf
ORDER BY sortkey;
答案 1 :(得分:0)
您的查询中有一个描述type
的错字。
您有:
WHEN type='Workflow::Tasks::UpdateDriverBankDetail'
但是数据库屏幕快照中的类型为复数。所以你应该有:
WHEN type='Workflow::Tasks::UpdateDriverBankDetails'
可能会有更多的错别字,但屏幕截图会截断数据。