select distinct(todouhuken_code),todouhuken_name, todouhuken_area_code2,area_name,ifnull(model_count,0) as cnt,model_maker_code
from
mst_todouhuken msto
right join
mst_area area on msto.todouhuken_area_code2 = area.area_code2
inner join
search_motorcycle sm on sm.dealer_todouhuken_code = msto.todouhuken_area_code
right join
mst_model_v2 v2 on sm.motorcycle_maker_code = v2.model_maker_code and sm.motorcycle_model_code =v2.model_code
where
motorcycle_jyoukyo in (1,5,6) and
model_maker_code = 4 and
dealer_todouhuken_code > 0
order by
todouhuken_area_code2,
todouhuken_code ;
mst_todouhuken msto
left join
mst_area area on msto.todouhuken_code = area.area_code
left join
search_motorcycle sm
on sm.dealer_todouhuken_code = msto.todouhuken_code
left join
mst_model_v2 v2
on v2.model_code = sm.motorcycle_model_code and sm.motorcycle_maker_code = v2.model_maker_code