gpt4 book ai didi

SQL - 指定的字母顺序

转载 作者:行者123 更新时间:2023-12-01 07:22:06 25 4
gpt4 key购买 nike

我想要 Completion_Status 列的特定顺序,如下所示:

已完成、通过、未完成和失败

我该如何订购?我想定义上面的顺序。

我试过 CASE 但它给了我一个错误,如期待 NUM 不是 CHAR。

select DISTINCT
u.first_name || ' ' || u.last_name "Employee_Name",
rco.title "Course_Name",
decode(p.status,'P','Passed', 'F','Failed', 'C','Completed', 'I','Incomplete', 'Not Attempted') "Completion_Status",

to_char(p.completed_date,'YYYY-MM-DD') "Date_Completed"
from
offering o, offering_enrollment oe, users u , performance p, offering_content_object c, content_object rco
where
o.id = oe.offering_id and
u.id = oe.user_id and
o.content_object_id = c.id AND
p.content_object_id = c.source_id and
p.content_object_id = rco.id AND
p.user_id(+) = u.id and
u.id in ( select id
from users
where manager_id = $user.id$)
AND
p.content_object_id NOT IN (41453457, 130020319, 43363877)
order by
"Employee_Name", "Completion_Status"

最佳答案

您可能可以使用以下内容:

ORDER BY "Employee_Name", CASE "Completed_Status"
WHEN 'Completed' THEN 0
WHEN 'Passed' THEN 1
WHEN 'Incomplete' THEN 2
WHEN 'Failed' THEN 3
ELSE 4
END;

您可能需要更改 CASE 以处理原始“p.status”值,在这种情况下,WHEN 条件也会发生变化:
ORDER BY "Employee_Name", CASE p.status
WHEN 'C' THEN 0
WHEN 'P' THEN 1
WHEN 'I' THEN 2
WHEN 'F' THEN 3
ELSE 4
END;

关于SQL - 指定的字母顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3763556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com