如何识别未随时间变化的条目?

时间:2016-12-25 05:51:57

标签: mysql sql

我正在尝试识别在一段时间内没有总分变化的名称,以及那段时间。

示例表:

+----------+--------+-------+
|   Date   |  Name  | Score |
+----------+--------+-------+
| 1/1/2016 | Frank  |    55 |
| 1/1/2016 | John   |    80 |
| 1/2/2016 | Frank  |    60 |
| 1/2/2016 | John   |    85 |
| 1/3/2016 | Frank  |    60 |
| 1/3/2016 | John   |   100 |
| 1/4/2016 | Frank  |    60 |
| 1/4/2016 | John   |   120 |
| 1/5/2016 | Frank  |    60 |
| 1/5/2016 | John   |   120 |
+----------+--------+-------+

预期产出:

+-------+------+
| Name  | Days |
+-------+------+
| Frank |    4 |
| John  |    2 |
+-------+------+

我一直试图弄清楚如何做到这一点却没有成功。我没有代码可以展示,因为它们都没有成功,只会使问题变得混乱。

我该怎么做呢?

1 个答案:

答案 0 :(得分:2)

您需要使用分数对数据进行分组,然后计算用户具有该分数的第一天和最后一天,请检查:

DATE

Date diff function返回两个package applications.android.dt.myapplication; import android.app.ProgressDialog; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.Button; import android.widget.ListView; import android.widget.PopupWindow; import org.json.JSONArray; import org.json.JSONObject; import java.util.HashMap; import askar.com.multiplerouteandroid.R; public class MainActivity extends AppCompatActivity { JSONObject jsonobject; JSONArray jsonarray; ListView listview; ListViewAdapter adapter; ProgressDialog mProgressDialog; ArrayList<HashMap<String, String>> arraylist; static String RANK = "id"; static String COUNTRY = "name"; static String FLAG = "image"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sub_menu); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get the view from listview_main.xml // Execute DownloadJSON AsyncTask new DownloadJSON().execute(); } // DownloadJSON AsyncTask private class DownloadJSON extends AsyncTask<Void, Void, Void> implements AdapterView.OnItemClickListener { // @Override // protected void onPreExecute() { // super.onPreExecute(); // Create a progressdialog // mProgressDialog = new ProgressDialog(SubMenu.this); // Set progressdialog title // mProgressDialog.setTitle("Categories of Main categories....."); // Set progressdialog message // mProgressDialog.setMessage("Loading..."); // mProgressDialog.setIndeterminate(false); // Show progressdialog // mProgressDialog.show(); // } @Override protected Void doInBackground(Void... params) { // Create an array arraylist = new ArrayList<HashMap<String, String>>(); // Retrieve JSON Objects from the given URL address jsonarray = JsonFunctions .getJSONfromURL("http://cloud.granddubai.com/broccoli/menu_typeitem.php"); try { // Locate the array name in JSON // jsonarray = jsonobject.getJSONArray("main_menu_items"); for (int i = 0; i < jsonarray.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); jsonobject = jsonarray.getJSONObject(i); // Retrive JSON Objects // map.put("id", jsonobject.getString("id")); map.put("name", jsonobject.getString("name")); map.put("image", jsonobject.getString("image")); // Set the JSON Objects into the array arraylist.add(map); } } catch (JSONException e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void args) { // Locate the listview in listview_main.xml listview = (ListView) findViewById(R.id.list1); // Pass the results into ListViewAdapter.java adapter = new ListViewAdapter(SubMenu.this, arraylist); // Set the adapter to the ListView listview.setAdapter(adapter); listview.setOnItemClickListener(this); // Close the progressdialog // mProgressDialog.dismiss(); } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE); View popupView = layoutInflater.inflate(R.layout.popup, null); final PopupWindow popupWindow = new PopupWindow( popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss); btnDismiss.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { popupWindow.dismiss(); }}); popupWindow.showAsDropDown(view, 50, -30); } } } 之间的差异,我们添加一个来表示该分数持续一天。

点击此处查看工作示例link