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

Select查询问题
一直开发ASP.NET + access 因需要而转成SQL,在ACCESS中 下列的代码没有报错的,但在SQL里就报错,

显示:关键字 'Group' 附近有语法错误。

Select [ban],Sum([Count]) from (
Select left([Class],2) as [ban],count(*) From [Point_Record] Where [Disponse] like '-%' group by [ban]
) Group by [ban] Order by Sum([Count]) Desc

求高手为小弟解答~

关键是 两个 select 不行

下面的又错在哪了?
Select sum(shu) from(select count(*) as [shu] From [Teacher] Where [Status] = 1 union all Select count(*) as [shu] From [Student] Where [Status] = 1)

------解决方案--------------------
Select [ban],Sum([Count]) from (
Select left([Class],2) as [ban],count(*) From [Point_Record] 
Where [Disponse] like '-%' group by left([Class],2)
) AS T Group by [ban] Order by Sum([Count]) Desc
------解决方案--------------------
Select sum(shu) from(select count(*) as [shu] From [Teacher] Where [Status] = 1 union all Select count(*) as [shu] From [Student] Where [Status] = 1) AS T
------解决方案--------------------
Select [ban],Sum([Count]) from (
Select left([Class],2) as [ban],count(*) From [Point_Record] Where [Disponse] like '-%' group by [ban]
) 加个别名,如a Group by [ban] Order by Sum([Count]) Desc

Select sum(shu) from(select count(*) as [shu] From [Teacher] Where [Status] = 1 union all Select count(*) as [shu] From [Student] Where [Status] = 1)a
------解决方案--------------------
SQL code
Select left(Class,2) ban , count(*) [count] 
From Point_Record 
Where Disponse like '-%'
Group by left(Class,2)
Order by [count] Desc