查询帮助,排名功能可能吗?

时间:2013-02-18 20:56:43

标签: sql

等级功能?任何人都可以帮助我。我希望我的查询只返回P0260字段的最低日期,以及绘画字段的最低日期。

JOB              ID     LINE                                   ORDER    RCVD     USE DATE
P0260           61785   1                   2400    24  10/26/2012
P0260           63462   3                   2400    24  11/14/2012
P0260           66372   1                   1   0   2/15/2013
P0260           66371   1                   5   0   3/1/2013
PAINTING    12246   1                   29  27  11/30/2006
PAINTING    30885   1                   160 0   9/29/2009
Painting    30885   2                   160 0   9/29/2009
PAINTING    31155   1                   25  0   11/6/2009

2 个答案:

答案 0 :(得分:1)

好的,在不知道你使用的RDBMS(和版本)的情况下,这个解决方案应该适用于大多数:

SELECT A.*
FROM YourTable A
INNER JOIN (SELECT JOB, MIN([USE DATE]) MinUseDate
            FROM YourTable
            GROUP BY JOB) B
    ON A.JOB = B.JOB AND A.[USE DATE] = B.MinUseDate

答案 1 :(得分:0)

SELECT query2.PART_ID,query2.ID,query2.LINE_NO,query2.DEL_SCHED_LINE_NO,query2.SYSADM_PURC_LINE_DEL.ORDER_QTY,query2.RECEIVED_QTY,query2.DESIRED_RECV_DATE,query2.SYSADM_PURC_ORDER_LINE.ORDER_QTY,query2.TOTAL_RECEIVED_QTY,query2。[USE DATE] FROM query2 INNER JOIN(SELECT query2.PART_ID,MIN(query2。[USE DATE])MinUseDate FROM query2 GROUP BY PART_ID)B ON query2.PART_ID = B.PART_ID AND query2。[USE DATE] = B.MinUseDate;