I have a question for SQL Group By Statement

First This is my table -> temp\_data

```
id    |   a_id     |      date_time         |    length  |   <br>
1074  |  3   |    2016-12-07 09:13:13.490  |  1.036013  |   <br>
1075  |  1   |    2016-12-07 09:13:13.690  |  1.699601  |   <br> 
1076  |  0   |    2016-12-07 09:13:13.867  |  2.110443  |   <br> 
1077  |  3   |    2016-12-07 09:13:14.490  |  1.027660  |   <br> 
1078  |  1   |    2016-12-07 09:13:14.690  |  1.742645  |   <br> 
1079  |  0   |    2016-12-07 09:13:14.867  |  2.121963  |   <br> 
1080  |  2   |    2016-12-07 09:13:18.390  |  4.008482  |   <br> 

```

I trying select id, a\_id, date\_time, length for 3 different a\_id order by id asc
so I use this

```
SELECT DISTINCT 
    a_id, 
    Min(id) id,         
    Min(Last_Data.lenght) lenght,
    (Select date_time from temp_data
     where temp_data.id = Min(Last_Data.id)) last_time
FROM (
    SELECT *
    FROM temp_data
    where id >= 1074 and id <= 1080
) Last_Data
GROUP BY a_id
order by id asc

```

The result is

```
id    |   a_id     |      last_time         |    length  |   <br>
1074  |  3   |    2016-12-07 09:13:13.490  |  1.013928 |   <br>
1075  |  1   |    2016-12-07 09:13:13.690  |  1.699601  |   <br>
1076  |  0   |    2016-12-07 09:13:13.867  |  2.110443  |   <br>

```

I get wrong length value for id. How can I solve this problem?

P.S. : First I get 3 different a\_id in this table. Then I use select top 3\* statement. Because two same a\_id can come in succession. For example

```
id  |   a_id     |      date_time         |    length  |   <br>
1074  |  1   |    2016-12-07 09:13:13.490  |  1.013928 |   <br>
1075  |  1   |    2016-12-07 09:13:13.690  |  1.699601  |   <br>

```