如何在mysql中进一步过滤GROUP BY记录?

时间:2015-09-11 06:48:08

标签: php mysql group-by

请检查我想要的完整ROW of query-id“43”的图像(以及另一个nic_id max query_id行),但它只给我max query_id,我尝试了不同的查询 - 例如:

private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
final ImageView imageView  = (ImageView) findViewById(R.id.arrows);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(final View view, final MotionEvent event) {
            //onFling();
            return true;
        }
    });
}


    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

        if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            Toast.makeText(this, "Opening Microsoft", Toast.LENGTH_LONG).show();
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.microsoft.com/"));
            startActivity(browserIntent);// Right to left

        }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            Toast.makeText(this, "Opening Roc van Twente", Toast.LENGTH_LONG).show();
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.rocvantwente.nl"));
            startActivity(browserIntent);// Left to right
        }

        if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
            Toast.makeText(this, "Opening Apple", Toast.LENGTH_LONG).show();
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.apple.com"));
            startActivity(browserIntent);// Bottom to top

        }  else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
            Toast.makeText(this, "Opening Oracle", Toast.LENGTH_LONG).show();
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.oracle.com"));
            startActivity(browserIntent);// Top to bottom
        }
        return false;
    }

当客户再次访问后续增加(+1)与他的相同nic_id与不同的主题。  only one customer data in table

我希望完成43行主题“Registration4”,日期等

不是这样,它应该是Registration4日期:2015-09-11 enter image description here

1 个答案:

答案 0 :(得分:0)

我在三个不同的页面中使用以下三个查询。我想IF MAX(Query_id)不具备特定的日期范围,然后忽略它。

/////////////   QUERY 1  \\\\\\\\\\\\\\\\\\\\\

$ sql =" SELECT * FROM sales_queries AS sq INNER JOIN(SELECT MAX(Query_id)AS MID FROM sales_queries,其中follow_up>'" $ s_date"' GROUP BY nic_id)AS subsq ON subsq.mId = sq.Query_id&#34 ;;

///////////// QUERY 2 \\\\\\\\\\\

$ sql =" SELECT * FROM sales_queries AS sq INNER JOIN(SELECT MAX(Query_id)AS {来自sales_queries follow_up之间{'"。$ s_date。"''''' 39;"。$ e_date。"' GROUP BY nic_id)AS subsq ON subsq.mId = sq.Query_id&#34 ;;

///////////// QUERY 3 \\\\\\\\\\\

$ sql =" SELECT * FROM sales_queries AS sq INNER JOIN(SELECT MAX(Query_id)AS MID FROM sales_queries,其中follow_up BETWEEN'" $ s_date"'与&# 39;"。$ e_date。"' GROUP BY nic_id)AS subsq ON subsq.mId = sq.Query_id&#34 ;;