2017-09-05 71 views
0

如何在選擇列時添加別名(AS)?我想實現這樣的:ORMLite爲列而不是表設置別名

SELECT `foo` AS `bar` FROM `xyz` WHERE `abc` = '123' ORDER BY `bar` 

我使用setAlias方法我selectColumns後立即嘗試,但它設置別名的表,我認爲這是意,因爲它是在docs提到。

回答

1

這裏是創建別名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

+0

只是一個後續問題,是否可以使用子查詢呢? –

+0

是的,你可以在subqry中使用,只需要維護** resultColumns **爲你想要的結果以及檢查上述鏈接描述@ GamatheGreat –

+0

plz檢查更新的答案@ GamatheGreat –