How to use the AS operator with the Library Room?

1

I'm not able to retrieve the variable total , how do I?

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

The IDE warns syntax error in the WHERE clause's total variable.

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;
    
asked by anonymous 05.05.2018 / 17:24

1 answer

1

The correct in the WHERE clause in your command would be >= not =>

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

This should work correctly.

AS would not work in this case.

    
05.05.2018 / 18:17