SELECTs.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)FROMgrid_station sLEFT JOIN grid_stake t ON s.GRID_STATION_SEQ = t.GRID_STATION_SEQLEFT JOIN evreadybase. DIRECTORY d ON d.query_code = 'charge.areacode' AND d.item_code = s.AREACODEWHEREs.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函数----