日期:2014-05-18  浏览次数:20587 次

高手帮看下,新手不会写SQL
SELECT   A.ID,A.Name,
            (SELECT   COUNT(B.ID)   FROM   Doc_List   B   WHERE   B.Doctype   =   A.ID   AND   B.PrjID=2)   As   DocCount
FROM   Doc_Type   A  
Where   (SELECT   COUNT(B.ID)   As   DocCount   FROM   Doc_List   B   WHERE   B.Doctype   =   A.ID   AND   B.PrjID=2)> 0
ORDER   BY   A.ID

这据SQL能执行,但感觉是不是重复了,效率低下,高手指教下应该怎么写!谢谢!

------解决方案--------------------
select
A.ID,A.Name,COUNT(B.ID) as DocCount
from
Doc_Type A,
Doc_List B
where
B.Doctype = A.ID and B.PrjID=2
group by
A.ID,A.Name