简体   繁体   中英

Get the less count id's PandaCode as the output

Please help me to resolve this issue i want to get the less size PandaCode as the output and i have an PandaCode

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

Each PandaCode code have multiple id s for example 37860 have count(id)=3 like this each Pandacode have id with count of different values but i want to get the PandaCode which is having less count of id as the output

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而不是每个,请试试这个

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM