1.查询数据表中重复的字段
es:需求查询下表 test表中 uid money target_type target_id 这四个字段值相同的数据
SQL语句:$sql = "select uid,money,target_type,target_id,count(*) as totalnum from test group by uid,money,target_type,target_id having totalunm>1 order by create_time DESC";
解释:先将数据按照四个字段分组(group by uid,money,target_type,target_id),然后统计出这四个字段相同值得条数(uid,money,target_type,target_id,count(*) as totalnum),然后过滤出条数大于1的数据(having totalunm>1),按照时间排序(order by create_time DESC).