查询去除重复记录

下面先来看看例子:
table
id name
1 a
2 b
3 c
4 c
5 b

select id, name from table group by name

/出发城市/

SELECT
  tptm.ID,
  cityInfo.`NAME` AS LEAVE_CITY
FROM
  t_p_trip_meal tptm
LEFT JOIN  t_dictionary city ON city.ID = tptm.LEAVE_CITY
LEFT JOIN t_dictionary_attach cityInfo ON cityInfo.NAME_CODE = city.NAME_CODE
AND cityInfo.LANG_ID = 'zh-cn'
WHERE
  tptm.IS_DEL = 0
GROUP BY
  LEAVE_CITY
ORDER BY
  tptm.CREATE_DATE,
  tptm.SORT DESC
select *, count(distinct name) from table group by name

猜你喜欢

转载自blog.csdn.net/pdsuxueyuan/article/details/86545168