php - 获取 less count id 的 PandaCode 作为输出

标签 php mysql sorting

请帮我解决这个问题 我想得到较小的 PandaCode 作为输出,我有一个 PandaCode

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

每个PandaCode代码都有多个id 例如 37860 有 count(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)'];
}

最佳答案

如果我以正确的方式理解您的问题而不是添加 whereIn 而不是为每个问题添加 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

关于php - 获取 less count id 的 PandaCode 作为输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40481291/

相关文章:

mysql - mac上安装MySql以及MySql与eclipse的连接

sql - 从 MySQL 表中检索和输入所有 "type",但仅检索每个 "type"的最新条目

javascript - 对包含长度值的数组进行排序

根据第 n 个元素对列表列表进行排序,然后是第 n+1 个元素,依此类推

php - Lithium - 如何获取获取的行数?

php - 使用单个查询更改多个 MySQL 字段 - 产品代码销售

mysql - 在 ORDER BY 中使用聚合函数与已经聚合的列之间是否存在性能差异?

php - 数据库错误: SQLSTATE[HY093]

php - PHP中有垃圾收集吗?

algorithm - 在 O(n) 时间内对 0...n 之间的 n 个数字的整数数组进行排序