如何在 Android 中使用 group by sqlite 查询
How to use group by sqlite query in Android
在 sqlite 中,按查询分组有效...但在 android 中查询无效...如何在 android 中使用按查询分组。
错误说:
Syntax error,Delete this token(Group by bname),
SELECT boname,bname,SUM(amount) FROM Auction where boname ="+boatno.getText().toString() Group by bname,null)
protected void adddata1() {
Database db=new Database(getActivity());
SQLiteDatabase sb=db.getReadableDatabase();
Cursor cus=sb.rawQuery("SELECT boname,bname,SUM(amount) FROM Auction where boname ="+boatno.getText().toString() Group by bname,null);//the problem line
cus.moveToFirst();
int j=0,k=0;
for(int i=0;i<cus.getCount();i++)
{
if(cus.getString(0).toString().equalsIgnoreCase(boatno.getText().toString()))
{
//Toast.makeText(getApplicationContext(), "entered",Toast.LENGTH_LONG).show();
bn.setText(cus.getString(1));
Log.e("", cus.getString(1));
amount.setText(cus.getString(2));
Log.e("", cus.getString(2));
adddata();
tr1.removeAllViewsInLayout();
adddata();
search.setClickable(false);
j++;
}
else
{
}
cus.moveToNext();
}
if(j==0)
{
Toast.makeText(getActivity(), "There is no data's on such Boat's",Toast.LENGTH_LONG).show();
}
}
在查询'(single quote)
中传递值
Cursor cus=sb.rawQuery("SELECT boname,bname,SUM(amount) FROM Auction where boname ='"+ boatno.getText().toString() +"' Group by bname",null);
在 sqlite 中,按查询分组有效...但在 android 中查询无效...如何在 android 中使用按查询分组。
错误说:
Syntax error,Delete this token(Group by bname), SELECT boname,bname,SUM(amount) FROM Auction where boname ="+boatno.getText().toString() Group by bname,null)
protected void adddata1() {
Database db=new Database(getActivity());
SQLiteDatabase sb=db.getReadableDatabase();
Cursor cus=sb.rawQuery("SELECT boname,bname,SUM(amount) FROM Auction where boname ="+boatno.getText().toString() Group by bname,null);//the problem line
cus.moveToFirst();
int j=0,k=0;
for(int i=0;i<cus.getCount();i++)
{
if(cus.getString(0).toString().equalsIgnoreCase(boatno.getText().toString()))
{
//Toast.makeText(getApplicationContext(), "entered",Toast.LENGTH_LONG).show();
bn.setText(cus.getString(1));
Log.e("", cus.getString(1));
amount.setText(cus.getString(2));
Log.e("", cus.getString(2));
adddata();
tr1.removeAllViewsInLayout();
adddata();
search.setClickable(false);
j++;
}
else
{
}
cus.moveToNext();
}
if(j==0)
{
Toast.makeText(getActivity(), "There is no data's on such Boat's",Toast.LENGTH_LONG).show();
}
}
在查询'(single quote)
中传递值
Cursor cus=sb.rawQuery("SELECT boname,bname,SUM(amount) FROM Auction where boname ='"+ boatno.getText().toString() +"' Group by bname",null);