/ *我需要比较事件编号相同的同一列中的2个日期。我已将日期从yyyymmdd hh:mm:ss转换为mm / dd / yyyy。我有以下数据我想比较:
event_date event_type event_sub_type
2013/01/16 filed
2013/01/10 pam edue
2013/01/01 pam edue
2013/04/01 filed
当我运行以下查询时,我没有收到任何数据。* /
SELECT
edue = (Select MIN(CONVERT(VARCHAR(10),EVENT_DATE, 101))
from tb_event e
where e.incident_id = vius_case.incident_id
and e.event_type = 'pam'
and e.event_sub_type = 'edue'),
filedt = (Select MIN(CONVERT(VARCHAR(10),EVENT_DATE, 101))
from tb_event f
where f.incident_id = vius_case.incident_id
and f.event_type = 'filed'
and f.event_sub_type = 'ref'),
vius_asa.Name,
vius_event.event_information,
vius_case.incident_no
FROM vius_case
join vius_event
on vius_case.incident_id = vius_event.incident_id
join vius_asa
on vius_case.incident_id = vius_asa.incident_id
join vius_incident_status
on vius_case.incident_id = vius_incident_status.incident_id
join tb_event
on vius_case.incident_id = tb_event.incident_id
WHERE vius_case.case_type not like 'e%'
AND vius_incident_status.case_status = 'O'
AND tb_event.event_type = 'filed' AND
( exists (Select incident_no from vius_event d1,vius_event d2
where d1.incident_id = vius_case.incident_id
and d2.incident_id = vius_case.incident_id
and d1.event_type = 'filed'
and d2.event_type = 'pam'
and d2.event_sub_type = 'edue'
and d1.event_date > d2.event_date))