我写了一段sql,数值不对,谁能帮忙看看哪地方错了
SELECT a.name,IfNULL(b.count,0) count from areac a left join (
SELECT
a.id,
a.NAME,
count(w.id) count
FROM
warn w,
vehicle v,
township t,
areac a
WHERE
w.device_no = v.device_no
AND v.prop_company_id = t.prop_company_id
AND t.area_id = a.id
AND v.be_deleted = 0
AND t.be_deleted = 0
GROUP BY
a.id
) b on a.id=b.id
where a.pid=371600
ORDER BY count desc
你先说说你要查什么,不然看得好累
select t4.name,count(*) as count from
(select t4.id,t4.name,t4.pid from warn t1
left join
vehicle t2
on t1.device_no=t2.device_no
left join
township t3
on t2.prop_company_id=t3.prop_company_id
left join
areac t4
on t3.area_id=t4.id
where t2.be_deleted = 0 and t3.be_deleted = 0
) t
where t.pid=371600
group by t.id
order by count desc
;