Oracle查询顺序
Oracle query order by
嗨,我的 DOMP_LOG_EVENT table
上有这些数据
DOCID DOC_VERSION CN_NO SEQ USERID EVENT_DESC DATE_LOG REMARKS UPLOAD_DATE
7a32bf6024264a109ce32d05c52d70f8 0 0 PHG01096 Document created 7/7/2020 8:44:36 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 PHG01096 Document Submitted for Review 7/7/2020 8:45:30 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 PHG00583 Document reviewed 7/7/2020 8:46:19 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 DOMSYS 3.0 Document Submitted for Approval 7/7/2020 8:46:19 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 NXP16848 Document Approved 7/7/2020 8:47:18 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 PHG01925 Document Approved 7/7/2020 8:48:09 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 DOMSYS 3.0 Document Submitted for Publication 7/7/2020 8:48:09 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 NXP74045 Document Published 7/7/2020 8:49:04 AM
7a32bf6024264a109ce32d05c52d70f8 0 0 PHG01096 Document Deployed 7/7/2020 8:50:33 AM
7a32bf6024264a109ce32d05c52d70f8 0 1 DOMSYS 3.0 Document Submitted for Deployment 7/7/2020 8:50:33 AM
我想得到这样的查询结果
Document Submitted for Deployment
应该在 Document Deployed
之前先走
这是我当前的查询
Select doc_version, date_log, event_desc, userid, nvl(fullname,userid) as fullname from domp_log_event A, dom_appusers b
where a.userid = b.username(+) and round(doc_version) = '0' and docid ='7a32bf6024264a109ce32d05c52d70f8' order by docid, date_log,userid DESC, seq ,doc_version
如何在不更改 table
上的数据的情况下实现它
我再次查看了示例数据,我认为以下 ORDER BY
会起作用:
ORDER BY DOCID,
DOC_VERSION DESC,
DATE_LOG,
DECODE(EVENT_DESC,'Document Submitted for Deployment',1,
'Document Deployed',2,
3) -- added this
嗨,我的 DOMP_LOG_EVENT table
上有这些数据DOCID DOC_VERSION CN_NO SEQ USERID EVENT_DESC DATE_LOG REMARKS UPLOAD_DATE
7a32bf6024264a109ce32d05c52d70f8 0 0 PHG01096 Document created 7/7/2020 8:44:36 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 PHG01096 Document Submitted for Review 7/7/2020 8:45:30 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 PHG00583 Document reviewed 7/7/2020 8:46:19 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 DOMSYS 3.0 Document Submitted for Approval 7/7/2020 8:46:19 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 NXP16848 Document Approved 7/7/2020 8:47:18 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 PHG01925 Document Approved 7/7/2020 8:48:09 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 DOMSYS 3.0 Document Submitted for Publication 7/7/2020 8:48:09 AM
7a32bf6024264a109ce32d05c52d70f8 0.01 0 NXP74045 Document Published 7/7/2020 8:49:04 AM
7a32bf6024264a109ce32d05c52d70f8 0 0 PHG01096 Document Deployed 7/7/2020 8:50:33 AM
7a32bf6024264a109ce32d05c52d70f8 0 1 DOMSYS 3.0 Document Submitted for Deployment 7/7/2020 8:50:33 AM
我想得到这样的查询结果
Document Submitted for Deployment
应该在 Document Deployed
这是我当前的查询
Select doc_version, date_log, event_desc, userid, nvl(fullname,userid) as fullname from domp_log_event A, dom_appusers b
where a.userid = b.username(+) and round(doc_version) = '0' and docid ='7a32bf6024264a109ce32d05c52d70f8' order by docid, date_log,userid DESC, seq ,doc_version
如何在不更改 table
上的数据的情况下实现它我再次查看了示例数据,我认为以下 ORDER BY
会起作用:
ORDER BY DOCID,
DOC_VERSION DESC,
DATE_LOG,
DECODE(EVENT_DESC,'Document Submitted for Deployment',1,
'Document Deployed',2,
3) -- added this