MySQL的左连接查询,只取出最⼤的⼀条数据
SELECT ID,USER_ID,problems,last_updated_date  FROM  (select * from t_iov_help_feedback  order by USER_ID, LAST_UPDATED_DATE DESC) b GROUP BY b.USER_ID;
SELECT * FROM TABLE WHERE ID IN (SELECT MAX(ID) FROM TABLE GROUP BY [去除重复的字段名列表,....])
参照这个格式,去重的写法。进⾏分组。
mysql删除重复的数据保留一条
最终,达到了我想要的结果。
SELECT
REVISIT_ID,
CONSULTATION_ID,
RESULT_NAME,
REVISIT_TIME
FROM
tb_cloud_consultation_revisit
WHERE REVISIT_ID IN
(SELECT
MAX(REVISIT_ID)
FROM
tb_cloud_consultation_revisit
GROUP BY CONSULTATION_ID )
SELECT
a.`CONSULTATION_ID` AS consultationId,
a.CONSULTATION_NAME AS consultationName,
a.CONSULTATION_PHONE AS consultationPhone,
a.CONSULTATION_DATE AS consultationDate,
a.MODE_NAME AS modeName,
a.`CHANNEL_NAME` AS channelName,
a.INTENTION_NAME AS intentionName,
a.REASON_NAME AS reasonName,
a.`PENSION_CARD` AS pensionCard,
a.REMARK AS remark,
a.PENSION_NAME AS pensionName,
a.ABILITY_NAME AS abilityName,
b.RESULT_NAME AS resultName
FROM
tb_cloud_consultation a
LEFT JOIN
(SELECT
REVISIT_ID,
CONSULTATION_ID,
RESULT_NAME,
REVISIT_TIME
FROM
tb_cloud_consultation_revisit
WHERE REVISIT_ID IN
(SELECT
MAX(REVISIT_ID)
FROM
tb_cloud_consultation_revisit
GROUP BY CONSULTATION_ID )
)
b
ON b.`CONSULTATION_ID` = a.`CONSULTATION_ID`

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。