sql优化
通过程序去访问,需要1.5分的样子才能返回结果,请问怎么优化sql语句
以下是语句
select u.c_old_user_id,
u.c_user_id,
u.c_user_name,
u.c_meter_number,
u.n_area_id,
u.c_user_address,
u.c_user_phone,
p.c_properties_name,
u.n_amount as n_now_balance,
t.c_meter_reader_name,
co.c_community_name,
re.n_reading_status,
s.d_meter_reading_date,
u.n_enter_type,
decode(u.n_meter_type, 0, '普通表', 1, '智能表', '远程表') as type,
(select wm_concat(to_char(d.n_detail_price, 'fm9999990.9999'))
from yx_detail d
where d.n_cost_id=1 and d.n_situation_id = s.n_situation_id) as detailPrice,
m.c_model_name,
u.c_meter_number,
p.c_properties_name,
min(s.n_degrees_start) as minStart,
max(s.n_degrees_end) as maxEnd,
sum(s.n_real_dosage) as totalDosage,
sum(s.n_amount) as totalAmount,
s.c_situation_use_month,
decode(s.n_charge_state, 0, '欠费', '已缴费') as chargeState
from yx_situation s , yx_user u
,yx_model m
,yx_properties p
, yx_mobile_reading_record re
, yx_community co
, yx_meter_reader t
where
1=1
and s.c_user_id = u.c_user_id
and s.n_model_id = m.n_model_id
and u.n_properties_id = p.n_properties_id
<!-- and re.c_user_id=u.c_user_id -->
and co.n_company_id=u.n_company_id
and t.n_company_id=u.n_company_id
<if test="userid!=null">
and u.c_user_id=#{userid}
</if>
<if test="meterNumber!=null">
and u.c_meter_number=#{meterNumber}
</if>
group by u.c_old_user_id,
u.c_user_id,
u.c_user_name,
u.n_enter_type,
u.n_company_id,
t.c_meter_reader_name,
co.c_community_name,
re.n_reading_status,
p.c_properties_name,
u.c_user_address,
u.n_area_id,
u.c_user_phone,
u.n_meter_type,
u.n_amount,
m.c_model_name,
u.c_meter_number,
p.c_properties_name,
s.c_situation_use_month,
s.n_charge_state,
s.d_meter_reading_date,
s.n_situation_id
order by s.c_situation_use_month desc