mysql count 28s到0.1s优化

SELECT
  s.GRID_STATION_name,
  d.item_cname,
  get_stake_cnt (t.GRID_STATION_seq),
  t.GRID_STAKE_SEQ,
  t.STACK_NO,
  t.CHECKCODE,
  (case t.STATUS when 1 then '离线'  when 2 then '故障' when 3 then '待机'  when 4 then '工作'  when 5 then '充电完成'  when 6 then '维修'end)
FROM
  grid_station s
LEFT JOIN grid_stake t ON s.GRID_STATION_SEQ = t.GRID_STATION_SEQ
LEFT JOIN evreadybase. DIRECTORY d ON d.query_code = 'charge.areacode' AND d.item_code = s.AREACODE
WHERE
  s.STATIONNO LIKE 'EV%'


(28s)

SELECT
 s.GRID_STATION_NAME as gridStationName,
 y.count as stakeCount,
 d.item_cname as areaName,
 t.GRID_STAKE_SEQ as gridStakeSeq,
 t.STACK_NO as stackNo,
 t.CHECKCODE as  checkCode,
 t.UPDATED_TIME as updatedTime,
 (case t.STATUS when 1 then '离线'  when 2 then '故障' when 3 then '待机'  when 4 then '工作'  when 5 then '充电完成'  when 6 then '维修'end) as status
 
 FROM
grid_station s 
 LEFT JOIN  grid_stake t ON s.GRID_STATION_SEQ = t.GRID_STATION_SEQ
 LEFT JOIN evreadybase.DIRECTORY d ON d.query_code = 'charge.areacode' AND d.item_code = s.AREACODE 
 LEFT JOIN (select grid_station_seq,count(1) as count from  grid_stake x GROUP BY GRID_STATION_SEQ) y on s.GRID_STATION_SEQ = y.grid_station_seq
 WHERE

  left(s.STATIONNO,2) ='EV' and s.DELETE_FLAG=0 

(0.1s)

添加索引


------------count函数----


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值