我使用distinct但是有一个重复的sql帮助我

时间:2015-04-12 10:54:56

标签: sql

select distinct  WORKORDER.WONUM ,  WORKORDER.SVCGRP ,WORKORDER.STATUS ,
WORKORDER.DESCRIPTION ,WORKORDER.REPORTDATE WO_DATE ,RFQLINE.ENTERDATE RFQ_DATE,
PRLINE.RFQNUM,PRLINE.PONUM ,PRLINE.prnum  ,PRLINE.ENTERDATE PR_DATE,POLINE.ENTERDATE
from workorder 
join PRLINE on workorder.wonum = prline.refwo 
JOIN RFQLINE ON  workorder.wonum =rfqline.refwo 
JOIN POLINE ON  workorder.wonum =PoLine.refwo 
where  WORKORDER.REPORTDATE between ('12/dec/12') and ('1/mar/15')
and WORKORDER.STATUS NOT IN ( 'CLOSE', 'CAN')
and WORKORDER.GLACCOUNT like '%ACAD-C0';



1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
1730382 43  WMATL   CUSC User Issues,Civil  09-JAN-13   15-NOV-14   4122    3624    3754    15-JAN-13   23-DEC-14
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899705 40  WMATL   Academic User Issues,OTHERS 15-JAN-14   04-JAN-15   4171    3648    5073    28-JAN-14   11-JAN-15
2899981 41  APPR    Academic User Issues,WATER PROOFING 25-JAN-14   14-SEP-14   4010    3489    5080    02-FEB-14   21-SEP-14
2900868 42  WMATL   Academic User Issues,WATER PROOFING 16-FEB-14   12-OCT-14   4065    3554    5148    25-FEB-14   02-NOV-14
2900868 42  WMATL   Academic User Issues,WATER PROOFING 16-FEB-14   12-OCT-14   4065    3554    5148    25-FEB-14   02-NOV-14
2900868 42  WMATL   Academic User Issues,WATER PROOFING 16-FEB-14   12-OCT-14   4065    3554    5148    25-FEB-14   02-NOV-14
3073377 41  WMATL   Academic User Issues,OTHERS 26-FEB-14   24-APR-14   3761    3600    5199    13-MAR-14   09-DEC-14
3073377 41  WMATL   Academic User Issues,OTHERS 26-FEB-14   24-APR-14   3761    3600    5199    13-MAR-14   09-DEC-14
3073377 41  WMATL   Academic User Issues,OTHERS 26-FEB-14   24-APR-14   3761    3600    5199    13-MAR-14   09-DEC-14
3073377 41  WMATL   Academic User Issues,OTHERS 26-FEB-14   24-APR-14   3761    3600    5199    13-MAR-14   09-DEC-14
3073383 41  WMATL   Academic User Issues,OTHERS 26-FEB-14   24-APR-14   3778    3601    5197    13-MAR-14   09-DEC-14
3073383 41  WMATL   Academic User Issues,OTHERS 26-FEB-14   24-APR-14   3778    3601    5197    13-MAR-14   09-DEC-14
3073383 41  WMATL   Academic User Issues,OTHERS 26-FEB-14   24-APR-14   3778    3601    5197    13-MAR-14   09-DEC-14
3073383 41  WMATL   Academic User Issues,OTHERS 26-FEB-14   24-APR-14   3778    3601    5197    13-MAR-14   09-DEC-14
3073388 41  WMATL   Academic User Issues,OTHERS 26-FEB-14   24-APR-14   3762    3612    5198    13-MAR-14   09-DEC-14

enter code here

1 个答案:

答案 0 :(得分:2)

我认为您从输出中看到重复的原因是因为您只在输出中显示没有时间的日期。每个WONUM日期(WO_DATE,RFQ_DATE)可能有多行。

如果您更改日期格式以包含时间:

alter session set nls_date_format='dd-MON-yy hh:mi:ss AM';

然后再次运行您的查询,您应该看到相同WONUM的行在同一天的时间不同。

如果您真的只想要日期的不同价值(无视时间),请将您的查询更改为:

select  distinct  WORKORDER.WONUM ,  WORKORDER.SVCGRP ,WORKORDER.STATUS ,
WORKORDER.DESCRIPTION ,trunc(WORKORDER.REPORTDATE) WO_DATE ,trunc(RFQLINE.ENTERDATE) RFQ_DATE,
PRLINE.RFQNUM,PRLINE.PONUM ,PRLINE.prnum  ,PRLINE.ENTERDATE PR_DATE,POLINE.ENTERDATE from ...