选择列时如何添加别名(AS)?我想实现以下目标:
SELECT `foo` AS `bar` FROM `xyz` WHERE `abc` = '123' ORDER BY `bar`
我已经在selectColumns之后尝试使用setAlias方法,但是它将别名设置为表,我认为这是自定义的,因为docs中已提及该别名。
最佳答案
这是创建别名check this的示例
String qry = "SELECT `foo` AS `bar` FROM `xyz` WHERE `abc` = '123' ORDER BY `bar`";
GenericRawResults<Foo> rawResults =
orderDao.queryRaw(qry, new RawRowMapper<Foo>() {
public Foo mapRow(String[] columnNames, String[] resultColumns) {
// assuming 0th field is the foo
return new Foo(resultColumns[0]));
}
});
// page through the results
for (Foo foo : rawResults) {
Log.e("result data ", "::" + foo.name");
}
rawResults.close();
您也可以通过this doc
关于android - ORMLite为列而不是表设置别名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46049393/