How to use the AS operator with the Library Room?

Asked

Viewed 11 times

1

I’m not getting the variable total, how do I do?

@Query("SELECT SUM(item_valor) AS total FROM Itens WHERE total =>:data")
Itens getMes(String data);

The IDE warns syntax error in the full variable of the WHERE Clause.

My Entity:

@Entity(tableName = AppContext.TABLE_ITENS)
public class Itens {
@PrimaryKey(autoGenerate = true)
private int itemId;

@ColumnInfo(name = "item_doc")
private String doc;

@ColumnInfo(name = "item_name")
private String name;

@ColumnInfo(name = "item_valor")
private Double valor;
  • Only with this explanation we have no way of knowing where you are using the code minimal example that explains the situation ...

  • A IDE avisa erro de sintaxe na variável total da Cláusula WHERE. has full surname of sum and in the where As a filter, can not that way and also total is what in your database? " ie, Cade the layout of this table???" how we can help if content is missing to identify the possible problem !!!

1 answer

1


The correct one in the clause WHERE at your command would be >= nay =>

@Query("SELECT SUM(item_valor) AS total FROM Itens WHERE SUM(item_valor) >= :data") Itens getMes(String data);

That way it should work properly.

The AS would not work in this case.

  • 1

    Got it @Enzo Tiezzi the correct is to use WHERE SUM(item_valor), thanks friend.

Browser other questions tagged

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