SELECT * FROM
(SELECT distinct
pu.user_number 服务号码,
dp.Access_time 入网时间,
dp.Product 产品,
dp.dev_organ_name 发展机构名称,
dp.Activity_name 合约名称,
nb.Det_batch_time 认定批次时间,
nb.Det_batch 批次,
pd.project_date 更新日期,
pd.project_name 项目状态,
pd.Responsible_project 当前项目人员,
pd.Business_units 往来单位,
3g_imsi.IMSI_code imsi码数据源对应,
3g_integral.date 3G返回值,
ou.Update_date 更新日期1,
ou.ACCT_CA_balance 账户当前可用余额,
ou.Real_time_calls 实时话费,
ou.Arrears 欠费,
ou.current_state 当前状态,
ou.package_flow 套餐内剩余流量,
ou.Tmonth_use_flow 本月已使用流_量不含免费流量,
ou.3Gflow_amount 3G流量_优惠总量,
ou.3Gflow_use 3G流量_优惠以用,
ou.3Gflow_surplus 3G流量_优惠剩余,
ou.CRBT 炫铃状态,
dq.Tm_call_num 当月主叫次数,
dq.Tm_Internet_MB 当月上网流量
FROM
project_use pu left JOIN
(SELECT * FROM obh_userdata ORDER BY obh_userdata.Update_date DESC) ou
ON pu.user_number=ou.Service_number
left join 3g_imsi on 3g_imsi.user_number=pu.user_number
left join 3g_integral on 3g_imsi.IMSI_code=3g_integral.imsi_imei
left join nun_batch nb on nb.Service_number=pu.user_number
left join dbss_pd dp on pu.user_number=dp.user_number
left join project_detail pd on pd.Service_number=pu.user_number
LEFT JOIN dbss_qa dq ON dq.number=pu.user_number
ORDER BY pd.project_date DESC)AS a
GROUP BY a.`服务号码`
(SELECT distinct
pu.user_number 服务号码,
dp.Access_time 入网时间,
dp.Product 产品,
dp.dev_organ_name 发展机构名称,
dp.Activity_name 合约名称,
nb.Det_batch_time 认定批次时间,
nb.Det_batch 批次,
pd.project_date 更新日期,
pd.project_name 项目状态,
pd.Responsible_project 当前项目人员,
pd.Business_units 往来单位,
3g_imsi.IMSI_code imsi码数据源对应,
3g_integral.date 3G返回值,
ou.Update_date 更新日期1,
ou.ACCT_CA_balance 账户当前可用余额,
ou.Real_time_calls 实时话费,
ou.Arrears 欠费,
ou.current_state 当前状态,
ou.package_flow 套餐内剩余流量,
ou.Tmonth_use_flow 本月已使用流_量不含免费流量,
ou.3Gflow_amount 3G流量_优惠总量,
ou.3Gflow_use 3G流量_优惠以用,
ou.3Gflow_surplus 3G流量_优惠剩余,
ou.CRBT 炫铃状态,
dq.Tm_call_num 当月主叫次数,
dq.Tm_Internet_MB 当月上网流量
FROM
project_use pu left JOIN
(SELECT * FROM obh_userdata ORDER BY obh_userdata.Update_date DESC) ou
ON pu.user_number=ou.Service_number
left join 3g_imsi on 3g_imsi.user_number=pu.user_number
left join 3g_integral on 3g_imsi.IMSI_code=3g_integral.imsi_imei
left join nun_batch nb on nb.Service_number=pu.user_number
left join dbss_pd dp on pu.user_number=dp.user_number
left join project_detail pd on pd.Service_number=pu.user_number
LEFT JOIN dbss_qa dq ON dq.number=pu.user_number
ORDER BY pd.project_date DESC)AS a
GROUP BY a.`服务号码`
当前问题共有如下(4)个解决方案
- 阿里服务器租用有子查询会很慢,你把子查询去掉
- gameof2008弄这么多嵌套,还有左联接 不慢才怪呢
- alick24索引值存在null会导致全表扫描
你的索引也不见得建的都合理 。
1:优化索引
2:分多条执行 , 创建临时表 ,减少连接的表