我有一个返回此查询的查询
我想返回这个,选择当天的最早时间
到目前为止,这是我的查询--- MIN(I.CREATIONDATE)
确实返回了我想要的日期时间格式,我希望MIN
将选择最早的时间。
SELECT TO_CHAR(MIN(I.INCIDENTID)) AS "Incident ID",
MIN(I.CREATIONDATE) AS "Creation Date",
TO_CHAR(I.CREATIONDATE,'MM-DD-YYYY') AS "Date",
TRIM(MO.DOMAINUSERNAME) AS "Login ID",
TRIM(M.MESSAGESUBJECT) AS "Email Subject"
FROM MESSAGE M
JOIN INCIDENT I
ON M.MESSAGESOURCE = I.MESSAGESOURCE
AND M.MESSAGEID = I.MESSAGEID
AND M.MESSAGEDATE = I.MESSAGEDATE
JOIN MESSAGEORIGINATOR MO
ON M.MESSAGEORIGINATORID = MO.MESSAGEORIGINATORID
GROUP BY TO_CHAR(I.CREATIONDATE,'MM-DD-YYYY'),
TRIM(MO.DOMAINUSERNAME),
TRIM(M.MESSAGESUBJECT)
答案 0 :(得分:1)
使用row_number()
with CTE as
(
select t1.*,
row_number() over (partition by trunc(creation_date) order by creation_date) rn
from Mytable t1
)
select *
from CTE
where rn = 1