获得较少计数id的PandaCode作为输出

时间:2016-11-08 07:31:16

标签: php mysql sorting

请帮我解决此问题 我希望得到更小的PandaCode作为输出,我有一个PandaCode

Array
(
    [0] => 37860
    [1] => 37016
    [2] => 37013
    [3] => 38220
    [4] => 38420
    [5] => 38223
)

每个PandaCode代码都有多个id个 例如37860有计数(id)= 3,每个Pandacode都有id,其中包含不同值的计数,但我希望得到PandaCode的计数较少的id foreach($pandacode as $dealer_code){ $query="SELECT COUNT(id) FROM `dealer_details` WHERE `PandaCode` like '$dealer_code' and `Senttime` like '%$today%'"; $result=mysqli_query($conn,$query); $row = $result->fetch_assoc(); $size = $row['COUNT(id)']; } 作为输出

listView=(ListView)findViewById(R.id.listview);


    Scanner s = null;
    try {
        s = new Scanner(new BufferedReader(new FileReader("/storage/sdcard0/client_new.txt")));
final ArrayList<String> list = new ArrayList<String>();
        while (s.hasNext()) {
            String str = s.next();
            char[] myChar = str.toCharArray();
            System.out.println(myChar);
            String str_new = String.valueOf(myChar);
            String[] items={str_new};

            for (int i = 0; i < items.length; ++i)
            {
                list.add(items[i]);
            }

            Toast.makeText(ExistingContacts.this,str_new,Toast.LENGTH_LONG).show();
            ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_dropdown_item,list);
            listView.setAdapter(adapter);


        }
    }catch (Exception e)
    {
        e.printStackTrace();;
    }

1 个答案:

答案 0 :(得分:0)

如果我以正确的方式理解您的问题,而不是添加whereIn而不是每个,请尝试此

SELECT COUNT(id) as ids FROM `dealer_details` WHERE `PandaCode` IN ($pandacode) and `Senttime` like '%$today%' GROUP BY `PandaCode` ORDER BY ids ASC LIMIT 1