SQL / Java query

1

Good morning, guys I'm a beginner in SQL and I need to do the following search.

Tenho esta tabela:
MINIMO    MAXIMO      CLASSE
    0        20         1
    21       40         2
    41       60         3 
    60       10000      4

I need a command to see which class fits the number 32. More precisely I'm using ORMLITE in Java

    
asked by anonymous 13.11.2016 / 14:12

2 answers

1

Considering that you are using OrmLite and you want a result similar to:

SELECT classe
  FROM tabela
 WHERE 32 BETWEEN minimo AND maximo

We'll need to create a query using queryBuilder of Dao. According to where documentation we will have:

Dao<Tabela, String> dao;
List<Tabela> resultados;

dao = DaoManager.createDao(conexao, Tabela.class);
resultados = dao.queryBuilder()
        .where()
        .le("mini‌​mo", 32)
        .and()
        .ge("maximo", 32)
        .query();

for (Tabela tabela : resultados) {
  System.out.println(tabela.getClasse());
}
  

le adds a '' clause so that the column is greater than or equal to the value.

    
13.11.2016 / 19:45
-1

You can do this:

SELECT 'CLASSE' FROM 'nome_da_tabela' WHERE 'MINIMO' <= 30 AND 'MAXIMO'  >= 30;
    
13.11.2016 / 16:34