我希望有一个查询可以从数据库中选择所有私有= 0的信息,除非用户='用户名'
像这样:
// Volley request
StringRequest stringRequest = new StringRequest(Request.Method.POST, URLUtils.URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jObj = new JSONObject(response);
if((jObj.getString("Ack").equals("1"))){
Toast.makeText(getApplicationContext(), jObj.getString("msg"), Toast.LENGTH_SHORT).show();
System.out.println(jObj.getString("image"));
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "VolleyError" + error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("auth", "abc167");
params.put("action", "editprofile");
params.put("first_name", fname_et.getText().toString());
params.put("last_name", lname_et.getText().toString());
params.put("address", address_str);
params.put("zipcode", zip_et.getText().toString());
params.put("phoneno", phone_et.getText().toString());
params.put("device_token_id", "1234567890");
params.put("device_type", "android");
params.put("lat", lat_str);
params.put("long", lng_str);
params.put("photo", imagepath);
params.put("userid", "121");
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
requestQueue.add(stringRequest);
答案 0 :(得分:3)
这是逻辑:
SELECT *
FROM table
WHERE private = 0 AND user != 'username';
此版本假定user
不是NULL
。
您可能会发现它更容易解释为:
SELECT *
FROM table
WHERE private = 0 AND NOT (user = 'username');
答案 1 :(得分:2)
SELECT * FROM table WHERE private = 0 AND user != 'username'
答案 2 :(得分:2)
回答原始问题:
SELECT * FROM table
WHERE private = 0
and user <> 'username'
编辑:OP添加了以下评论:
如果我想选择private = 0,除非private = 1且user =&#39; username&#39;
然后听起来你只是想要这个(但它不是100%清楚):
SELECT * FROM table
WHERE private = 0
OR (private = 1 and user = 'username')
答案 3 :(得分:1)
SELECT * FROM table_name
WHERE private = 0 AND user != 'username'