gpt4 book ai didi

sql - PostgreSQL Order By 无法正常工作

转载 作者:行者123 更新时间:2023-11-29 13:39:08 26 4
gpt4 key购买 nike

我在 PostgreSQL 数据库中工作,我想在选择查询中获取数据,但根据我的要求,我的订单无法正常工作。我怎样才能做到这一点?

现在我正在按以下顺序获取数据

1
1
1A
10
10
10A
10A
11A
11A
12A
2
2
2A
cradle-1
cradle-2
cradle-11

我想按以下顺序获取数据。

1
1
2
2
10
10
1A
2A
10A
10A
11A
11A
12A
cradle-1
cradle-2
cradle-11

下面是我从中获取所有数据的选择查询。

select am.audit_ques_id, am.audit_id  ,ddl3.dd_value AS activityName  , am.question_id , 
ddl2.question AS question, am.answer_type, am.answer_lov, ddl4.dd_value AS answerTypeName, am.ok_notok ,
ddl5.dd_value AS okNotOkName, am.answer_min, am.answer_max, am.uom, ddl13.dd_value AS uomname,
am.correct_ans, am.created_by, am.created_date,ddl6.dd_value AS stage, ddl14.dd_value AS stageno,
ddl7.description, ddl8.dd_value AS severity, ddl9.dd_value AS who , ddl10.dd_value AS how ,
ddl11.dd_value AS "when" , ddl12.dd_value AS "where" from audit_ques_detail am
left join audit_master ddl1 on ddl1.audit_id=am.audit_id
left join dd_type_details ddl3 on ddl3.dd_id=ddl1.activity_id
left join question_master ddl2 on ddl2.question_id=am.question_id
left join dd_type_details ddl4 on ddl4.dd_id = am.answer_type
left join dd_type_details ddl5 on ddl5.dd_id = am.ok_notok
left join dd_type_details ddl6 on ddl6.dd_id = ddl2.stage
left join question_master ddl7 on ddl7.question_id = am.question_id
left join dd_type_details ddl8 on ddl8.dd_id = ddl2.severity
left join dd_type_details ddl9 on ddl9.dd_id = ddl2.who
left join dd_type_details ddl10 on ddl10.dd_id = ddl2.how
left join dd_type_details ddl11 on ddl11.dd_id = ddl2.when
left join dd_type_details ddl12 on ddl12.dd_id = ddl2.where
left join dd_type_details ddl13 on ddl13.dd_id = am.uom
left join dd_type_details ddl14 on ddl14.dd_id = am.stage_no
where am.audit_id = 1581 and am.isActive = 1 ORDER BY ddl14.dd_value

最佳答案

由于您可以使用多个排序条件,首先按值的长度排序,然后按升序排序。

order by length(ddl14.dd_value), ddl14.dd_value

关于sql - PostgreSQL Order By 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58080589/

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