SQL Left Join问题 解决立马结帖

happy664618843 happy664618843 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
EMR_ProcessUReadMessage表数据如下:一共6条
EMR_Code CreateByPlatform IsRead
201707130001 Doctor 1
201707130001 Desgin 0
201707130001 Medicine 1
201707130001 Doctor 1
201707130001 Desgin 0
201707130001 Medicine 1


doctor_essays 表 两条记录:数据如下
EMR_Code doctorRemarkDate doctorRemark
201707130001 2017.07.14 14:19:00 添加一条未读信息
201707130001 2017.07.14 14:08:42 测试未读

simple_EMR表数据只有一条:
EMR_Code patient_Name patient_Age patient_Sex patient_Tel
201707130001 测试医学服务中心New 2017-08-16 1 15221105698

SQL语句如下:
 SELECT    dess.EMR_Code , H.isRead, 'Remark' as RecordType,H.CreateByPlatform,
dess.doctorRemark AS 'message' ,
dess.createDate

FROM dbo.doctor_essays dess

LEFT join dbo.simple_EMR E on dess.EMR_Code=E.EMR_Code
LEFT join EMR_ProcessUReadMessage H on H.EMR_Code=dess.EMR_Code
WHERE dess.EMR_Code = '201707130001' and H.CreateByPlatform='Doctor'
AND dess.flag = 1


查询出来的结果如下:
EMR_Code isRead RecordType CreateByPlatform message createDate
201707130001 1 Remark Doctor 添加一条未读信息 2017-07-14 14:19:04.167
201707130001 1 Remark Doctor 添加一条未读信息 2017-07-14 14:19:04.167
201707130001 1 Remark Doctor 测试未读 2017-07-14 14:08:45.170
201707130001 1 Remark Doctor 测试未读 2017-07-14 14:08:45.170

最终我想得到结果如下:请问各位高手如何实现??
EMR_Code isRead RecordType CreateByPlatform message createDate
201707130001 1 Remark Doctor 添加一条未读信息 2017-07-14 14:19:04.167
201707130001 1 Remark Doctor 测试未读 2017-07-14 14:08:45.170
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
happy664618843
MS-SQL Server 34,876 成员 254,635 内容