首页 新闻 搜索 专区 学院

多表子查询sql优化问题

0
悬赏园豆:10 [已解决问题] 解决于 2013-07-25 00:30

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

hangkai的主页 hangkai | 初学一级 | 园豆:193
提问于:2013-03-06 11:33
< >
分享
最佳答案
0

try use view or procedure

收获园豆:10
zhibudao | 小虾三级 |园豆:525 | 2013-03-06 12:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册