sql 使用distinct 后还有重复数据

weimei521 weimei521 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
SELECT distinct a.* FROM mz_ht_result a   inner  join yp_mz_base b on a.charge_code=b.charge_code
inner join a_employee_mi c on a.op_id=c.code
INNER join mz_charge_detail d on a.patient_id=d.patient_id and a.times=d.times and
a.receipt_no=d.receipt_no and a.order_no=d.order_no and a.item_no=d.item_no
WHERE a.patient_id='P10798773-0 ' and a.times=3
and d.real_no>0 order by a.order_no,a.real_no


这是有两条记录,但是如果加上查询b表的数据,就会重复
select DISTINCT a.id, d.pay_mark,drugname,ht_result,ht_time,validate_time,op_id,op_name=c.name,op_time,ht_remark,
a.patient_id,a.times,a.receipt_no,a.order_no,a.item_no,a.real_no,d.input_id
from mz_ht_result a
inner join yp_mz_base b on a.charge_code=b.charge_code
inner join a_employee_mi c on a.op_id=c.code
INNER join mz_charge_detail d on a.patient_id=d.patient_id and a.times=d.times and
a.receipt_no=d.receipt_no and a.order_no=d.order_no and a.item_no=d.item_no
where a.patient_id='P10798773-0 ' and a.times=3
and d.real_no>0 order by a.order_no,a.real_no

这样会有4条数据,请问第二条要怎么改
...全文
评论 6
收藏 已收藏
分享
返回顶部
weimei521
疑难问题 22,298 成员 121,727 内容