如何在显示时从同一个表中删除重复记录

时间:2014-04-28 04:52:40

标签: sql oracle oracle10g

我有桌子DEMO

CUST_ID    DATE_ENQ
---------- ---------
30         28-APR-14 
31         27-APR-14 
30         27-APR-14 

我想输出类似这样的东西

COUNT(CUST_ID) DATE_ENQ
-------------- ---------
             2 27-APR-14 
             1 28-APR-14 

6 个答案:

答案 0 :(得分:1)

DELETE FROM
   DEMO D1
WHERE
  D1.rowid >
   ANY (
     SELECT
        D2.rowid
     FROM
        DEMO D2
     WHERE
        D1.CUST_ID = D2.CUST_ID
        );

答案 1 :(得分:1)

请尝试:

SELECT 
  *
FROM tbl
WHERE rowid in
  (SELECT MIN(rowid)
  FROM tbl
  GROUP BY DATE_ENQ);

SQL Fiddle Demo

答案 2 :(得分:1)

尝试Thiz

select count(CUST_ID),TO_CHAR(DATE_ENQ,'DD-MON-YYYY') from demo group by TO_CHAR(DATE_ENQ,'DD-MON-YYYY');

SQL Fiddle Demo Click Here

答案 3 :(得分:0)

试试这个 -

select cust_id, min(date_enq) as Datez, COUNT(cust_id) as Custs
from tbl
group by cust_id

答案 4 :(得分:0)

您将获得上面提到的输出。我已经检查过这是有效的

SELECT count(CUST_ID), DATE_ENQ FROM Demo GROUP BY DATE_ENQ;

谢谢和问候

答案 5 :(得分:0)

SELECT COUNT(*) as TotalCustomers,DATE_ENQ
FROM tableName
GROUP BY DATE_ENQ
ORDER BY TotalCustomers