GROUP BY的一些常用用法
1、删除数据库表里重复的数据
$sql="select id from flight group by food,prise,num,number"; $res=mysqli_query($con,$sql); $str=''; while($info=mysqli_fetch_array($res)){ $str .=$info['id'].','; } $str_id=rtrim($str,','); $sql="DELETE FROM flight WHERE id not in ($str_id)";
2、未读的聊天消息条数
fromuserid收到的消息用户id,touserid本用户的id
$sql="SELECT sum(is_read) AS num from chat_merchant where fromuserid = '{$r['fromuserid']}' and touserid = '{$r['touserid']}' and is_read=1 group by fromuserid";