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