SQL Access group by 使用注意事项

数据库笔记 ningjian

SQL Access group by 使用注意事项

在MS SQL 中正常的语句:

1
select Field1,sum(Field2) as Field2n from Tables where group by Field1 order by Field2 desc

在Access中会报错:

主要原因是受后缀:order by 的影响,它会把order by 的参数当做合计函数的一部分,应该改成:

1
2
3
select from (
    select Field1,sum(Field2) as Field2n from Tables where group by Field1
order by Field2 desc

  

 

 

发表评论:

验证码