标签:distinct lis span varchar mysql logs bsp ati car
1. 关联查询,关联部分结果,避免重复
a left join b on a.id = b.aid a与b为一对多关系,查询出来的结果必然是a中数据重复,不同的地方在于查询出的b属性.
查询结果不让a重复,一对多,多的部分用集合表示
<resultMap id="Map1" type="com.young.Model"> <id column="id" jdbcType="BIGINT" property="id" /> ...... <collection property="treatmentMethodList" column="id" ofType="com.young.Treatment"> <result column="name" jdbcType="VARCHAR" property="name" /> </collection>
column 代表数据库字段,property代表对象中的属性,两者之间为映射关系.collection中的result为查询出的关联部分的属性,一对多,多合并为集合,一还是一,结果中一不会应为一对多而出现重复.
select mmc.id ,mmc...,mtt.name from mml_card mmc left join mt_treatment mtt on mmc.id = mtt.medical_card_id
2. 按类型分组查询某个条件的数量
select tumour_kind_name tumourKindName,COUNT(DISTINCT patient_id) shouldFollow from mss_medical_card mmc WHERE YEAR(DATE_ADD(mmc.confirmed_date,INTERVAL mmc.cycle day)) = YEAR(‘2017-06-01 20:14:12‘) and is_death = 0 group by tumourKindName;
标签:distinct lis span varchar mysql logs bsp ati car
原文地址:http://www.cnblogs.com/yangfei-beijing/p/6606767.html