SELECT name,
(SELECT COUNT(id)
FROM class
WHERE f_grade_id = 1 AND type = dbo.basicmess.id) AS todal
FROM dbo.basicmess
WHERE (type = 1)
------解决方案--------------------
try
SELECT A.name,
COUNT(B.id) AS todal
FROM dbo.basicmess A
Left Join class B
On B.f_grade_id = 1 AND B.type = A.id
WHERE (A.type = 1)