SQL/Java query

Asked

Viewed 402 times

1

Good morning, guys I am 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 am using the ORMLITE in Java

  • Try this: seuDAO.queryBuilder(). selectColumns("name"). Where(). le("minimo", 32). and(). ge("maximo", 32);

  • Has any response helped solve the problem and can address similar questions from other users? If so, make sure to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).

2 answers

1

Whereas you are using the Ormlite and that you want a result similar to:

SELECT classe
  FROM tabela
 WHERE 32 BETWEEN minimo AND maximo

We will need to create a query using the queryBuilder of Dao. According to Where documentation we shall 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 less-than or equal to the value.

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

-1

You can do it like this:

SELECT `CLASSE` FROM `nome_da_tabela` WHERE `MINIMO` <= 30 AND `MAXIMO`  >= 30;
  • also search between

  • Actually he specified that he is using ORMLITE, IE, it is not a query exactly that he wants

Browser other questions tagged

You are not signed in. Login or sign up in order to post.