首页 > 代码库 > MySQL DISTINCT

MySQL DISTINCT

DISTINCT(COL)用来对结果去除重复

比如表内容如下:

技术分享

SELECT DISTINCT(id)
FROM yww_test

技术分享


下面的例子实现:选择过去一天,没有出现过的数据

-- 统计最原始的未上线采集数据,准备和其他表合并
DROP VIEW if EXISTS `unconnected_elemeterhead`;
CREATE VIEW unconnected_elemeterhead
AS
SELECT
	DATE_SUB(curdate() , INTERVAL 1 DAY) as 'uhead_date', 
  head.`NAME` as 'uhead_name',
	head.PADDRESS as head_address,
	head.E_BUREAU_ID as bureau_id,
	head.ID as 'uhead_id'
FROM
	e_elemeterhead_link39 AS head
WHERE
	head.`STATUS` = 0
AND head.ID NOT IN (
	SELECT DISTINCT
		(a.E_ELEMETERHEAD_ID)
	FROM
		e_eledata AS a
	WHERE
		to_days(now()) - to_days(a.DLDT) = 1
);
注意:如何确定昨天,如何统计未出现的ID

MySQL DISTINCT