SELECT
count(nvo.id) AS total,
(
SELECT count(nvo1.id)
FROM nyl_vAS_orders AS nvo1
WHERE nvo1.to_number!='' AND nvo1.app_id
IN (
SELECT na1.id FROM nyl_archives AS na1 WHERE na1.typeid=na.typeid
)
)
AS to_number,
(
SELECT count(nvo2.id)
FROM nyl_vAS_orders AS nvo2
WHERE nvo2.to_number!='' AND nvo2.rstate = 1 AND nvo2.app_id
IN (
SELECT na1.id FROM nyl_archives AS na1 WHERE na1.typeid=na.typeid
)
)
AS r_number,
nat.typename,nat.id AS type_id FROM nyl_vas_orders AS nvo
LEFT JOIN nyl_archives AS na ON nvo.app_id=na.id
LEFT JOIN nyl_arctype AS nat ON na.typeid=nat.id
GROUP BY na.typeid
ORDER BY total desc
LIMIT 10
try use view or procedure