日期:2014-05-18 浏览次数:20722 次
SELECT T_qualityEvent.F_eventId, T_qualityEvent.F_eventName, T_qualityEvent. F_eventContent,T_qualityEvent.F_source,per.F_perName ,per.F_dptName, T_qualityType.F_typeName, CASE T_qualityEvent.F_isComplete WHEN 1 THEN '已完成' WHEN 0 THEN '未完成' END AS F_isComplete, CASE T_qualityEvent.F_isComment WHEN 1 THEN '是' WHEN 0 THEN '否' END AS F_isComment, CASE T_qualityEvent.F_source WHEN 1 THEN '客户' WHEN 0 THEN '内部' END AS F_source, T_qualityEvent.F_log,comment.F_commentDate,comment.F_commentCont,comPer.F_perName as commentPer --改为t_per的别名comper FROM T_qualityEvent INNER JOIN VI_Per AS per ON per.F_perSid = T_qualityEvent.F_iptPer INNER JOIN T_qualityType ON T_qualityType.F_typeId=T_qualityEvent.F_typeId INNER JOIN( --有批注内容,取最后一条批注信息 SELECT T_qualityEventComment.F_eventId,T_qualityEventComment.F_commentDate,T_qualityEventComment.F_commentCont,comPer.F_perName FROM T_qualityEventComment INNER JOIN T_per AS comPer ON comPer.F_perId = T_qualityEventComment.F_perId WHERE 1=1 -- --@2@ AND T_qualityEventComment.F_commentId IN (SELECT MAX(F_commentId)as F_commentid FROM T_qualityEventComment AS T_qualityEventComment_2 ) UNION ALL --无批注内容 SELECT * FROM( SELECT T_qualityEvent.F_eventId,T_qualityEvent.F_iptDate AS F_commentDate,T_qualityEvent.F_eventContent,comPer.F_perName AS F_comName FROM T_qualityEvent INNER JOIN T_perList ON T_perList.F_perSId=T_qualityEvent.F_iptPer INNER JOIN T_per AS comPer ON comPer.F_perId = T_perList.F_perId --这儿去掉一个等于号 WHERE NOT EXISTS (SELECT F_eventId FROM T_qualityEventComment AS T_qualityEventComment_1 WHERE ( F_eventId =T_qualityEvent.F_eventId)) ) AS T_qualityEventComment WHERE 1=1 ----@2@ )AS comment ON comment.F_eventId=T_qualityEvent.F_eventId
------解决方案--------------------
INNER JOIN T_perList ON T_perList.F_perSId=T_qualityEvent.F_iptPer
INNER JOIN T_per A