SQL query using order by filtering through the records [closed]

1

I have the table:

| cod | hora  | produto | Amostra | Min | Max |
|-----|-------|---------|---------|-----|-----|
|   1 | 08:00 |  96722  |   1     | 100 | 200 |
|   2 | 08:23 |  96721  |   1     | 90  | 90  |
|   3 | 08:50 |  96722  |   2     | 100 | 100 |
|   4 | 09:50 |  96722  |   2     | 100 | 200 |
|   5 | 08:30 |  96721  |   2     | 90  | 90  |
|   6 | 08:28 |  96721  |   1     | 12  | 25  |

I want you to list me like this:

| cod | hora  | produto | Amostra | Min | Max |
|-----|-------|---------|---------|-----|-----|
|   2 | 08:23 |  96721  |   1     | 90  | 90  |
|   5 | 08:30 |  96721  |   2     | 90  | 90  |
|   6 | 08:28 |  96721  |   1     | 12  | 25  |
|   1 | 08:00 |  96722  |   1     | 100 | 200 |
|   4 | 09:50 |  96722  |   2     | 100 | 200 |
|   3 | 08:50 |  96722  |   2     | 100 | 100 |

I'm trying to do it this way:

select * from tb_tabela
order by
tb_tabela.produto,
tb_tabela.amostra,
tb_tabela.hora

It is returning me wrong, as below:

| cod | hora  | produto | Amostra | Min | Max |
|-----|-------|---------|---------|-----|-----|
|   2 | 08:23 |  96721  |   1     | 90  | 90  |
|   6 | 08:28 |  96721  |   1     | 12  | 25  | //errado
|   5 | 08:30 |  96721  |   2     | 90  | 90  |
|   1 | 08:00 |  96722  |   1     | 100 | 200 |
|   3 | 08:50 |  96722  |   2     | 100 | 100 | //errado
|   4 | 09:50 |  96722  |   2     | 100 | 200 |
    
asked by anonymous 06.09.2016 / 16:08

1 answer

0

Test this query

select * from tb_tabela
order by
tb_tabela.produto ASC,
tb_tabela.Max DESC,
tb_tabela.Min DESC

should work (edited)

    
06.09.2016 / 16:23