怎么去掉多表查询重复data
select P_recorduserinfo.id,Scrsize,SellChannelId,PlatFormId,Phone,Imsi,Imei,Pv,DownTime,dateadd(yy,1,downtime) as overtime,count(distinct P_recorduserinfo.id),
(COALESCE((select province from mes_Phone_Province where phoneSub=SUBSTRING(phone,1,7) or 86+phoneSub=SUBSTRING(phone,1,9)),(select province from mes_ip_city where ipid=pipid))) as province
from P_recorduserinfo left join mes_ip_city on P_recorduserinfo.PIpId=mes_ip_city.ipid
group by P_recorduserinfo.id,Scrsize,SellChannelId,PlatFormId,Phone,Imsi,Imei,Pv,DownTime,P_recorduserinfo.PIpId
因为我的province是根据两个表优先抉择的,所以用到了COALESCE函数,然而这么查的时候数据达几万了,本来是没这么多数据的,大虾们帮忙看看,解决下,小妹感激不尽....
------解决方案--------------------select Distinct P_recorduserinfo.id,Scrsize,SellChannelId,PlatFormId,Phone,Imsi,Imei,Pv,DownTime,dateadd(yy,1,downtime) as overtime,count(distinct P_recorduserinfo.id),
(COALESCE((select province from mes_Phone_Province where phoneSub=SUBSTRING(phone,1,7) or 86+phoneSub=SUBSTRING(phone,1,9)),(select province from mes_ip_city where ipid=pipid))) as province
from P_recorduserinfo left join mes_ip_city on P_recorduserinfo.PIpId=mes_ip_city.ipid
group by P_recorduserinfo.id,Scrsize,SellChannelId,PlatFormId,Phone,Imsi,Imei,Pv,DownTime,P_recorduserinfo.PIpId
试试
------解决方案--------------------这。。。。。。。。看不懂
------解决方案--------------------你的left jion 是不是有多行对一行的情况呢?
------解决方案--------------------P_recorduserinfo.PIpId与mes_ip_city.ipid是不是一对多的关系?