vendredi 16 octobre 2015

Sql 2005 sub query

I have A wo_records table, want to be able to extract the current work order for each machine with the start time. I wrote this query to rank each records and gives the latest entry a rank of 1, but I'm unable to nest it where I can use A where clause (where rank =1)

SELECT  * ,
        RANK() over ( PARTITION BY get_address order by t_start desc)  AS    Last_value
        FROM  wo_records 


ndx|Wo        | t_start                 |t_end               | get_address| Rank
--------------------------------------------------------------------------------
45  12521231    2019-01-07 15:41:24.000 NULL                    44           1
46  12521231    2018-01-08 15:42:24.000 2018-01-08 15:47:24.000 44           2
39  12521231    2016-01-21 15:43:24.000 2016-01-21 15:49:24.000 44           3

What is the correct way to nest this statement to retrieve only the rows with rank= 1?

Thanks,

Aucun commentaire:

Enregistrer un commentaire